fix migration
This commit is contained in:
parent
5070ec2ac7
commit
a07ada7de0
29
migrate.py
29
migrate.py
|
@ -118,6 +118,18 @@ def shouts(content_data, shouts_by_slug, shouts_by_oid):
|
||||||
try: limit = int(sys.argv[2]) if len(sys.argv) > 2 else len(content_data)
|
try: limit = int(sys.argv[2]) if len(sys.argv) > 2 else len(content_data)
|
||||||
except ValueError: limit = len(content_data)
|
except ValueError: limit = len(content_data)
|
||||||
|
|
||||||
|
with local_session() as session:
|
||||||
|
community = session.query(Community).filter(Community.id == 0).first()
|
||||||
|
if not community:
|
||||||
|
Community.create(**{
|
||||||
|
'id' : 0,
|
||||||
|
'slug': 'discours.io',
|
||||||
|
'name': 'Дискурс',
|
||||||
|
'pic': 'https://discours.io/images/logo-min.svg',
|
||||||
|
'createdBy': '0',
|
||||||
|
'createdAt': date_parse(OLD_DATE)
|
||||||
|
})
|
||||||
|
|
||||||
if not topics_by_cat:
|
if not topics_by_cat:
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
topics = session.query(Topic).all()
|
topics = session.query(Topic).all()
|
||||||
|
@ -328,17 +340,6 @@ if __name__ == '__main__':
|
||||||
elif cmd == "topics":
|
elif cmd == "topics":
|
||||||
topics(export_topics, topics_by_slug, topics_by_cat, topics_by_tag, cats_data, tags_data)
|
topics(export_topics, topics_by_slug, topics_by_cat, topics_by_tag, cats_data, tags_data)
|
||||||
elif cmd == "shouts":
|
elif cmd == "shouts":
|
||||||
with local_session() as session:
|
|
||||||
community = session.query(Community).filter(Community.id == 0).first()
|
|
||||||
if not community:
|
|
||||||
Community.create(**{
|
|
||||||
'id' : 0,
|
|
||||||
'slug': 'discours.io',
|
|
||||||
'name': 'Дискурс',
|
|
||||||
'pic': 'https://discours.io/images/logo-min.svg',
|
|
||||||
'createdBy': '0',
|
|
||||||
'createdAt': date_parse(OLD_DATE)
|
|
||||||
})
|
|
||||||
shouts(content_data, shouts_by_slug, shouts_by_oid) # NOTE: listens limit
|
shouts(content_data, shouts_by_slug, shouts_by_oid) # NOTE: listens limit
|
||||||
elif cmd == "comments":
|
elif cmd == "comments":
|
||||||
for comment in comments_data:
|
for comment in comments_data:
|
||||||
|
@ -349,10 +350,8 @@ if __name__ == '__main__':
|
||||||
users(users_by_oid, users_by_slug, users_data)
|
users(users_by_oid, users_by_slug, users_data)
|
||||||
topics(export_topics, topics_by_slug, topics_by_cat, topics_by_tag, cats_data, tags_data)
|
topics(export_topics, topics_by_slug, topics_by_cat, topics_by_tag, cats_data, tags_data)
|
||||||
shouts(content_data, shouts_by_slug, shouts_by_oid)
|
shouts(content_data, shouts_by_slug, shouts_by_oid)
|
||||||
cl = sys.argv[2] if len(sys.argv) > 2 else 10
|
for comment in comments_data:
|
||||||
topOids = sorted([ c[0] for c in comments_by_post.items()], reverse=True, key=lambda i: len(i[1]))[-cl:]
|
migrateComment(comment)
|
||||||
topSlugs = [ shouts_by_oid[oid]['slug'] for oid in topOids ]
|
|
||||||
comments(topSlugs, export_comments, export_articles, shouts_by_slug, content_dict)
|
|
||||||
elif cmd == 'slug':
|
elif cmd == 'slug':
|
||||||
export_slug(sys.argv[2], export_articles, export_authors, content_dict)
|
export_slug(sys.argv[2], export_articles, export_authors, content_dict)
|
||||||
#export_finish(export_articles, export_authors, export_topics, export_comments)
|
#export_finish(export_articles, export_authors, export_topics, export_comments)
|
||||||
|
|
|
@ -36,7 +36,6 @@ def migrate(entry):
|
||||||
shout: Int!
|
shout: Int!
|
||||||
deletedAt: DateTime
|
deletedAt: DateTime
|
||||||
deletedBy: Int
|
deletedBy: Int
|
||||||
rating: Int
|
|
||||||
ratings: [CommentRating]
|
ratings: [CommentRating]
|
||||||
views: Int
|
views: Int
|
||||||
old_id: String
|
old_id: String
|
||||||
|
@ -54,8 +53,9 @@ def migrate(entry):
|
||||||
'body': html2text(entry['body']),
|
'body': html2text(entry['body']),
|
||||||
'shout': shout.id
|
'shout': shout.id
|
||||||
}
|
}
|
||||||
if 'rating' in entry:
|
#TODO save as CommentRating
|
||||||
comment_dict['rating'] = entry['rating']
|
#if 'rating' in entry:
|
||||||
|
# comment_dict['rating'] = entry['rating']
|
||||||
if entry.get('deleted'):
|
if entry.get('deleted'):
|
||||||
comment_dict['deletedAt'] = date_parse(entry['updatedAt'])
|
comment_dict['deletedAt'] = date_parse(entry['updatedAt'])
|
||||||
comment_dict['deletedBy'] = str(entry['updatedBy'])
|
comment_dict['deletedBy'] = str(entry['updatedBy'])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user