consistent naming of database fields

This commit is contained in:
Igor Lobanov
2022-11-29 20:13:03 +01:00
parent c064170d24
commit 8209cc744c
20 changed files with 113 additions and 114 deletions

View File

@@ -73,8 +73,7 @@ async def migrate(entry, storage):
Shout
).where(Shout.slug == shout_dict["slug"]).one()
reaction_dict["shout_id"] = shout.id
reaction_dict["shoutId"] = shout.id
reaction_dict["createdBy"] = author.id if author else 1
reaction_dict["kind"] = ReactionKind.COMMENT
@@ -92,13 +91,13 @@ async def migrate(entry, storage):
).where(
User.id == reaction_dict["createdBy"]
).filter(
ShoutReactionsFollower.shout_id == reaction.shout_id
ShoutReactionsFollower.shoutId == reaction.shoutId
).first()
if not following1:
following1 = ShoutReactionsFollower.create(
follower_id=reaction_dict["createdBy"],
shout_id=reaction.shout_id,
followerId=reaction_dict["createdBy"],
shoutId=reaction.shoutId,
auto=True
)
session.add(following1)
@@ -110,7 +109,7 @@ async def migrate(entry, storage):
).join(
Topic
).where(
TopicFollower.follower_id == reaction_dict["createdBy"]
TopicFollower.followerId == reaction_dict["createdBy"]
).filter(
Topic.slug == t
).first()
@@ -121,8 +120,8 @@ async def migrate(entry, storage):
).where(Topic.slug == t).one()
topic_following = TopicFollower.create(
follower_id=reaction_dict["createdBy"],
topic_id=topic.id,
followerId=reaction_dict["createdBy"],
topicId=topic.id,
auto=True
)
session.add(topic_following)
@@ -135,7 +134,7 @@ async def migrate(entry, storage):
.first()
)
re_reaction_dict = {
"shout_id": reaction_dict["shout_id"],
"shoutId": reaction_dict["shoutId"],
"replyTo": reaction.id,
"kind": ReactionKind.LIKE
if comment_rating_old["value"] > 0
@@ -151,14 +150,14 @@ async def migrate(entry, storage):
following2 = session.query(
ShoutReactionsFollower
).where(
ShoutReactionsFollower.follower_id == re_reaction_dict['createdBy']
ShoutReactionsFollower.followerId == re_reaction_dict['createdBy']
).filter(
ShoutReactionsFollower.shout_id == rr.shout_id
ShoutReactionsFollower.shoutId == rr.shoutId
).first()
if not following2:
following2 = ShoutReactionsFollower.create(
follower_id=re_reaction_dict['createdBy'],
shout_id=rr.shout_id,
followerId=re_reaction_dict['createdBy'],
shoutId=rr.shoutId,
auto=True
)
session.add(following2)
@@ -191,13 +190,13 @@ def migrate_2stage(rr, old_new_id):
session.add(comment)
srf = session.query(ShoutReactionsFollower).where(
ShoutReactionsFollower.shout_id == comment.shout_id
ShoutReactionsFollower.shoutId == comment.shoutId
).filter(
ShoutReactionsFollower.follower_id == comment.createdBy
ShoutReactionsFollower.followerId == comment.createdBy
).first()
if not srf:
srf = ShoutReactionsFollower.create(shout_id=comment.shout_id, follower_id=comment.createdBy, auto=True)
srf = ShoutReactionsFollower.create(shoutId=comment.shoutId, followerId=comment.createdBy, auto=True)
session.add(srf)
session.commit()

View File

@@ -91,12 +91,12 @@ async def create_shout(shout_dict, userslug):
).join(
User
).where(
ShoutReactionsFollower.shout_id == s.id
ShoutReactionsFollower.shoutId == s.id
).filter(
User.slug == userslug
).first()
if not srf:
srf = ShoutReactionsFollower.create(shout_id=s.id, follower_id=follower.id, auto=True)
srf = ShoutReactionsFollower.create(shoutId=s.id, followerId=follower.id, auto=True)
session.add(srf)
session.commit()
@@ -226,15 +226,15 @@ async def add_topics_follower(entry, storage, userslug):
tf = session.query(
TopicFollower
).where(
TopicFollower.follower_id == follower.id
TopicFollower.followerId == follower.id
).filter(
TopicFollower.topic_id == topic.id
TopicFollower.topicId == topic.id
).first()
if not tf:
tf = TopicFollower.create(
topic_id=topic.id,
follower_id=follower.id,
topicId=topic.id,
followerId=follower.id,
auto=True
)
session.add(tf)
@@ -325,7 +325,7 @@ async def topics_aftermath(entry, storage):
.first()
)
if shout_topic_old:
shout_topic_old.update({"topic_id": new_topic.id})
shout_topic_old.update({"topicId": new_topic.id})
else:
shout_topic_new = (
session.query(ShoutTopic)
@@ -338,7 +338,7 @@ async def topics_aftermath(entry, storage):
if not shout_topic_new:
try:
ShoutTopic.create(
**{"shout_id": shout.id, "topic_id": new_topic.id}
**{"shoutId": shout.id, "topicId": new_topic.id}
)
except Exception:
print("[migration] shout topic error: " + newslug)
@@ -373,14 +373,14 @@ async def content_ratings_to_reactions(entry, slug):
if content_rating["value"] > 0
else ReactionKind.DISLIKE,
"createdBy": reactedBy.id,
"shout_id": shout.id,
"shoutId": shout.id,
}
cts = content_rating.get("createdAt")
if cts:
reaction_dict["createdAt"] = date_parse(cts)
reaction = (
session.query(Reaction).filter(
Reaction.shout_id == reaction_dict["shout_id"]
Reaction.shoutId == reaction_dict["shoutId"]
).filter(
Reaction.createdBy == reaction_dict["createdBy"]
).filter(

View File

@@ -123,15 +123,15 @@ def migrate_2stage(entry, id_map):
user_rating_dict = {
"value": rating_entry["value"],
"rater_id": rater.id,
"user_id": user.id,
"raterId": rater.id,
"userId": user.id,
}
user_rating = UserRating.create(**user_rating_dict)
if user_rating_dict['value'] > 0:
af = AuthorFollower.create(
author_id=user.id,
follower_id=rater.id,
authorId=user.id,
followerId=rater.id,
auto=True
)
session.add(af)