migration script fix
This commit is contained in:
@@ -16,16 +16,18 @@ def migrate(entry):
|
||||
'slug': entry['slug'],
|
||||
# 'createdBy': entry['createdBy'],
|
||||
# 'createdAt': date_parse(entry['createdAt']),
|
||||
'title': entry['title'], #.lower(),
|
||||
'title': entry['title'].replace(' ', ' '), #.lower(),
|
||||
'children': [],
|
||||
'community' : Community.default_community.slug,
|
||||
'body' : entry.get('description')
|
||||
}
|
||||
try:
|
||||
with local_session() as session:
|
||||
topic = session.query(Topic).filter(Topic.slug == entry['slug']).first()
|
||||
if not topic:
|
||||
topic = Topic.create(**topic_dict)
|
||||
topic = session.query(Topic).filter(Topic.slug == topic_dict['slug']).first()
|
||||
if not topic:
|
||||
topic = session.query(Topic).filter(Topic.title == topic_dict['title']).first()
|
||||
if not topic:
|
||||
topic = Topic.create(**topic_dict)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
raise e
|
||||
|
@@ -5,36 +5,39 @@ from orm import Topic, Community
|
||||
from dateutil.parser import parse as date_parse
|
||||
|
||||
def migrate(entry):
|
||||
'''
|
||||
type Topic {
|
||||
slug: String! # ID
|
||||
createdBy: Int! # User
|
||||
createdAt: DateTime!
|
||||
title: String
|
||||
parents: [String] # NOTE: topic can have parent topics
|
||||
children: [String] # and children
|
||||
}
|
||||
'''
|
||||
if type(entry['createdAt']) == type(''):
|
||||
ts = date_parse(entry['createdAt'])
|
||||
else:
|
||||
ts = datetime.fromtimestamp(entry['createdAt']/1000)
|
||||
topic_dict = {
|
||||
'slug': entry['slug'],
|
||||
# 'createdBy': entry['createdBy'],
|
||||
# 'createdAt': ts,
|
||||
'title': entry['title'], # .lower(),
|
||||
'children': [],
|
||||
'community' : Community.default_community.slug,
|
||||
'body' : entry.get('description')
|
||||
}
|
||||
try:
|
||||
with local_session() as session:
|
||||
topic = session.query(Topic).filter(Topic.slug == entry['slug']).first()
|
||||
if not topic: topic = Topic.create(**topic_dict)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
raise e
|
||||
|
||||
topic_dict['tag_id'] = entry['_id']
|
||||
return topic_dict
|
||||
'''
|
||||
type Topic {
|
||||
slug: String! # ID
|
||||
createdBy: Int! # User
|
||||
createdAt: DateTime!
|
||||
title: String
|
||||
parents: [String] # NOTE: topic can have parent topics
|
||||
children: [String] # and children
|
||||
}
|
||||
'''
|
||||
if type(entry['createdAt']) == type(''):
|
||||
ts = date_parse(entry['createdAt'])
|
||||
else:
|
||||
ts = datetime.fromtimestamp(entry['createdAt']/1000)
|
||||
topic_dict = {
|
||||
'slug': entry['slug'],
|
||||
# 'createdBy': entry['createdBy'],
|
||||
# 'createdAt': ts,
|
||||
'title': entry['title'].replace(' ', ' '), # .lower(),
|
||||
'children': [],
|
||||
'community' : Community.default_community.slug,
|
||||
'body' : entry.get('description')
|
||||
}
|
||||
try:
|
||||
with local_session() as session:
|
||||
topic = session.query(Topic).filter(Topic.slug == topic_dict['slug']).first()
|
||||
if not topic:
|
||||
topic = session.query(Topic).filter(Topic.title == topic_dict['title']).first()
|
||||
if not topic:
|
||||
topic = Topic.create(**topic_dict)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
raise e
|
||||
|
||||
topic_dict['tag_id'] = entry['_id']
|
||||
return topic_dict
|
||||
|
Reference in New Issue
Block a user