some migration fix

This commit is contained in:
tonyrewin 2022-09-05 05:09:44 +03:00
parent 71f3ac5ed6
commit 616463e3da

View File

@ -72,7 +72,7 @@ async def migrate(entry, storage):
} }
else: else:
userdata = User.default_user.dict() userdata = User.default_user.dict()
assert userdata, "no user found for %s from " % [oid, len(users_by_oid.keys())] assert userdata, "no user found for %s from %d" % [oid, len(users_by_oid.keys())]
r["authors"] = [ r["authors"] = [
userdata, userdata,
] ]
@ -220,7 +220,7 @@ async def migrate(entry, storage):
ShoutTopic.create( ShoutTopic.create(
**{"shout": shout_dict["slug"], "topic": newslug} **{"shout": shout_dict["slug"], "topic": newslug}
) )
except: except Exception:
print("[migration] shout topic error: " + newslug) print("[migration] shout topic error: " + newslug)
session.commit() session.commit()
if newslug not in shout_dict["topics"]: if newslug not in shout_dict["topics"]:
@ -269,15 +269,14 @@ async def migrate(entry, storage):
) )
reaction.update(reaction_dict) reaction.update(reaction_dict)
else: else:
day = (reaction_dict.get("createdAt") or ts).replace( reaction_dict['day'] = (reaction_dict.get("createdAt") or ts).replace(
hour=0, minute=0, second=0, microsecond=0 hour=0, minute=0, second=0, microsecond=0
) )
rea = Reaction.create(**reaction_dict) rea = Reaction.create(**reaction_dict)
await ReactedStorage.increment(rea) await ReactedStorage.increment(rea)
# shout_dict['ratings'].append(reaction_dict) # shout_dict['ratings'].append(reaction_dict)
except: except Exception:
print("[migration] content_item.ratings error: \n%r" % content_rating) raise Exception("[migration] content_item.ratings error: \n%r" % content_rating)
raise Exception
# shout views # shout views
ViewedByDay.create(shout=shout_dict["slug"], value=entry.get("views", 1)) ViewedByDay.create(shout=shout_dict["slug"], value=entry.get("views", 1))