migration removed

This commit is contained in:
2022-07-21 19:01:28 +03:00
parent 379fb6fb68
commit a627bfe043
29 changed files with 1 additions and 4829 deletions

View File

@@ -1,28 +0,0 @@
from migration.extract import extract, html2text
from orm.base import local_session
from orm import Topic, Community
def migrate(entry):
body_orig = entry.get('description', '').replace(' ', ' ')
topic_dict = {
'slug': entry['slug'],
'oid': entry['_id'],
'title': entry['title'].replace(' ', ' '), #.lower(),
'children': [],
'community' : Community.default_community.slug
}
topic_dict['body'] = extract(html2text(body_orig), entry['_id'])
with local_session() as session:
slug = topic_dict['slug']
topic = session.query(Topic).filter(Topic.slug == slug).first()
if not topic:
topic = Topic.create(**topic_dict)
if len(topic.title) > len(topic_dict['title']):
topic.update({ 'title': topic_dict['title'] })
if len(topic.body) < len(topic_dict['body']):
topic.update({ 'body': topic_dict['body'] })
session.commit()
# print(topic.__dict__)
rt = topic.__dict__.copy()
del rt['_sa_instance_state']
return rt