2022-09-17 18:12:14 +00:00
|
|
|
import json
|
2022-08-11 09:14:12 +00:00
|
|
|
import os
|
2022-09-17 18:12:14 +00:00
|
|
|
|
2022-08-11 09:14:12 +00:00
|
|
|
import bson
|
2022-12-14 06:53:44 +00:00
|
|
|
import gc
|
2022-08-11 10:06:31 +00:00
|
|
|
from .utils import DateTimeEncoder
|
2022-08-11 09:14:12 +00:00
|
|
|
|
|
|
|
|
2022-09-03 10:50:14 +00:00
|
|
|
def json_tables():
|
|
|
|
print("[migration] unpack dump/discours/*.bson to migration/data/*.json")
|
|
|
|
data = {
|
|
|
|
"content_items": [],
|
|
|
|
"content_item_categories": [],
|
|
|
|
"tags": [],
|
|
|
|
"email_subscriptions": [],
|
|
|
|
"users": [],
|
|
|
|
"comments": [],
|
|
|
|
}
|
|
|
|
for table in data.keys():
|
2022-12-14 06:53:44 +00:00
|
|
|
gc.collect()
|
2022-09-03 10:50:14 +00:00
|
|
|
lc = []
|
|
|
|
with open("dump/discours/" + table + ".bson", "rb") as f:
|
|
|
|
bs = f.read()
|
|
|
|
f.close()
|
|
|
|
base = 0
|
|
|
|
while base < len(bs):
|
|
|
|
base, d = bson.decode_document(bs, base)
|
|
|
|
lc.append(d)
|
|
|
|
data[table] = lc
|
|
|
|
open(os.getcwd() + "/migration/data/" + table + ".json", "w").write(
|
|
|
|
json.dumps(lc, cls=DateTimeEncoder)
|
|
|
|
)
|