Fix JSON to Mongo migration (#2346)

Signed-off-by: Toby Harradine <tobyharradine@gmail.com>
This commit is contained in:
Toby Harradine 2018-12-29 10:51:31 +11:00 committed by GitHub
parent 3a8da1f82b
commit 2bd05a5a04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import argparse
import asyncio
import json
@ -177,26 +176,21 @@ def basic_setup():
async def json_to_mongo(current_data_dir: Path, storage_details: dict):
from redbot.core.drivers.red_mongo import Mongo
core_data_file = list(current_data_dir.glob("core/settings.json"))[0]
m = Mongo("Core", "0", **storage_details)
core_data_file = current_data_dir / "core" / "settings.json"
driver = Mongo(cog_name="Core", identifier="0", **storage_details)
with core_data_file.open(mode="r") as f:
core_data = json.loads(f.read())
collection = m.get_collection()
await collection.update_one(
{"_id": m.unique_cog_identifier}, update={"$set": core_data["0"]}, upsert=True
)
data = core_data.get("0", {})
for key, value in data.items():
await driver.set(key, value=value)
for p in current_data_dir.glob("cogs/**/settings.json"):
cog_name = p.parent.stem
with p.open(mode="r") as f:
cog_data = json.loads(f.read())
cog_i = None
for ident in list(cog_data.keys()):
cog_i = str(hash(ident))
cog_m = Mongo(p.parent.stem, cog_i, **storage_details)
cog_c = cog_m.get_collection()
for ident in list(cog_data.keys()):
await cog_c.update_one(
{"_id": cog_m.unique_cog_identifier}, update={"$set": cog_data[cog_i]}, upsert=True
)
cog_data = json.load(f)
for identifier, data in cog_data.items():
driver = Mongo(cog_name, identifier, **storage_details)
for key, value in data.items():
await driver.set(key, value=value)
async def mongo_to_json(current_data_dir: Path, storage_details: dict):