From 1254b1416395ece2d88c049f2a092fc69e409140 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Wed, 17 Aug 2022 12:07:14 +0300 Subject: [PATCH] migration fixes --- migration/tables/comments.py | 8 +++----- migration/tables/content_items.py | 7 ++++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/migration/tables/comments.py b/migration/tables/comments.py index 72dca84f..cbc47b3e 100644 --- a/migration/tables/comments.py +++ b/migration/tables/comments.py @@ -4,8 +4,7 @@ from orm import Reaction, User from base.orm import local_session from migration.html2text import html2text from orm.reaction import ReactionKind -from orm.shout import Shout -from services.stat.reacted import ReactedByDay +from services.stat.reacted import ReactedStorage ts = datetime.now() @@ -73,7 +72,7 @@ def migrate(entry, storage): # creating reaction from old comment day = (reaction_dict.get('createdAt') or ts).replace(hour=0, minute=0, second=0, microsecond=0) reaction = Reaction.create(**reaction_dict) - ReactedByDay.create(shout=reaction.shout, reaction=reaction.id, kind=reaction.kind, day=day) + ReactedStorage.increment(reaction) reaction_dict['id'] = reaction.id for comment_rating_old in entry.get('ratings',[]): @@ -90,8 +89,7 @@ def migrate(entry, storage): try: # creating reaction from old rating rr = Reaction.create(**re_reaction_dict) - day = (re_reaction_dict.get('createdAt') or ts).replace(hour=0, minute=0, second=0, microsecond=0) - ReactedByDay.create(shout=rr.shout, reaction=rr.id, kind=rr.kind, day=day, replyTo=reaction.id) + ReactedStorage.increment(rr) except Exception as e: print('[migration] comment rating error: %r' % re_reaction_dict) diff --git a/migration/tables/content_items.py b/migration/tables/content_items.py index e279956a..9471c51d 100644 --- a/migration/tables/content_items.py +++ b/migration/tables/content_items.py @@ -1,7 +1,7 @@ from dateutil.parser import parse as date_parse import sqlalchemy from orm.shout import Shout, ShoutTopic, User -from services.stat.reacted import ReactedByDay +from services.stat.reacted import ReactedStorage from services.stat.viewed import ViewedByDay from transliterate import translit from datetime import datetime @@ -162,7 +162,8 @@ def migrate(entry, storage): print('[migration] something went wrong with shout: \n%r' % shout_dict) raise e session.commit() - except: + except Exception as e: + print(e) print(s) raise Exception @@ -217,7 +218,7 @@ def migrate(entry, storage): else: day = (reaction_dict.get('createdAt') or ts).replace(hour=0, minute=0, second=0, microsecond=0) rea = Reaction.create(**reaction_dict) - ReactedByDay.create(shout=rea.shout, reaction=rea.id, kind=rea.kind, day=day) + ReactedStorage.increment(rea) # shout_dict['ratings'].append(reaction_dict) except: print('[migration] content_item.ratings error: \n%r' % content_rating)