This commit is contained in:
2023-01-17 09:19:12 +03:00
parent 261b22716b
commit 910c191b0d
4 changed files with 112 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ from migration.tables.content_items import get_shout_slug
from migration.tables.content_items import migrate as migrateShout
from migration.tables.topics import migrate as migrateTopic
from migration.tables.users import migrate as migrateUser
from migration.tables.remarks import migrate as migrateRemark
from migration.tables.users import migrate_2stage as migrateUser_2stage
from orm.reaction import Reaction
from orm import init_tables
@@ -135,6 +136,15 @@ async def shouts_handle(storage, args):
print("[migration] " + str(anonymous_author) + " authored by @anonymous")
async def remarks_handle(storage):
print("[migration] comments")
c = 0
for entry_remark in storage["remarks"]["data"]:
remark = await migrateRemark(entry_remark)
c += 1
print("[migration] " + str(c) + " remarks migrated")
async def comments_handle(storage):
print("[migration] comments")
id_map = {}
@@ -169,6 +179,8 @@ async def all_handle(storage, args):
await users_handle(storage)
await topics_handle(storage)
print("[migration] users and topics are migrated")
await remarks_handle(storage)
print("[migration] remarks are migrated")
await shouts_handle(storage, args)
print("[migration] migrating comments")
await comments_handle(storage)
@@ -210,6 +222,11 @@ def data_load():
content_data = json.loads(open("migration/data/content_items.json").read())
storage["shouts"]["data"] = content_data
print("[migration.load] " + str(len(content_data)) + " content items ")
remarks_data = json.loads(open("migration/data/remarks.json").read())
storage["remarks"]["data"] = remarks_data
print("[migration.load] " + str(len(remarks_data)) + " remarks data ")
# fill out storage
for x in users_data:
storage["users"]["by_oid"][x["_id"]] = x

View File

@@ -0,0 +1,32 @@
from base.orm import local_session
from migration.extract import extract_md
from migration.html2text import html2text
from orm.remark import Remark
def migrate(entry):
print(entry)
break
remark = {
"slug": entry["slug"],
"oid": entry["_id"],
"body": extract_md(html2text(
entry['body'] + entry['textAfter'] or '' + \
entry['textBefore'] or '' + \
entry['textSelected'] or ''
), entry["_id"])
}
with local_session() as session:
slug = remark["slug"]
rmrk = session.query(Remark).filter(Remark.slug == slug).first() or Remark.create(
**tooltip
)
if not rmrk:
raise Exception("no rmrk!")
if rmrk:
Remark.update(rmrk, remark)
session.commit()
rt = tt.__dict__.copy()
del rt["_sa_instance_state"]
return rt