Add some errors for backend conversions and only allow MongoV2 creation (#2570)

* Add some errors for conversions and only allow mongoV2 creation

* Add another message

* Fixed message to be more clear
This commit is contained in:
Will 2019-04-10 20:42:28 -04:00 committed by GitHub
parent 2776db0cf9
commit c82ac5ae68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -28,8 +28,13 @@ def get_driver(type, *args, **kwargs):
from .red_json import JSON from .red_json import JSON
return JSON(*args, **kwargs) return JSON(*args, **kwargs)
elif type == "MongoDB": elif type == "MongoDBV2":
from .red_mongo import Mongo from .red_mongo import Mongo
return Mongo(*args, **kwargs) return Mongo(*args, **kwargs)
elif type == "Mongo":
raise RuntimeError(
"Please convert to JSON first to continue using the bot."
" This is a required conversion prior to using the new Mongo driver."
)
raise RuntimeError("Invalid driver type: '{}'".format(type)) raise RuntimeError("Invalid driver type: '{}'".format(type))

View File

@ -114,7 +114,7 @@ def get_storage_type():
print() print()
print("Please choose your storage backend (if you're unsure, choose 1).") print("Please choose your storage backend (if you're unsure, choose 1).")
print("1. JSON (file storage, requires no database).") print("1. JSON (file storage, requires no database).")
print("2. MongoDB (not recommended, currently unstable)") print("2. MongoDB")
storage = input("> ") storage = input("> ")
try: try:
storage = int(storage) storage = int(storage)
@ -260,9 +260,9 @@ async def edit_instance():
if confirm("Would you like to change the storage type? (y/n):"): if confirm("Would you like to change the storage type? (y/n):"):
storage = get_storage_type() storage = get_storage_type()
storage_dict = {1: "JSON", 2: "MongoDB"} storage_dict = {1: "JSON", 2: "MongoDBV2"}
default_dirs["STORAGE_TYPE"] = storage_dict[storage] default_dirs["STORAGE_TYPE"] = storage_dict[storage]
if storage_dict.get(storage, 1) == "MongoDB": if storage_dict.get(storage, 1) == "MongoDBV2":
from redbot.core.drivers.red_mongo import get_config_details from redbot.core.drivers.red_mongo import get_config_details
storage_details = get_config_details() storage_details = get_config_details()
@ -272,12 +272,16 @@ async def edit_instance():
raise NotImplementedError("We cannot convert from JSON to MongoDB at this time.") raise NotImplementedError("We cannot convert from JSON to MongoDB at this time.")
# if confirm("Would you like to import your data? (y/n) "): # if confirm("Would you like to import your data? (y/n) "):
# await json_to_mongo(current_data_dir, storage_details) # await json_to_mongo(current_data_dir, storage_details)
else: elif storage_dict.get(storage, 1) == "JSON":
storage_details = instance_data["STORAGE_DETAILS"] storage_details = instance_data["STORAGE_DETAILS"]
default_dirs["STORAGE_DETAILS"] = {} default_dirs["STORAGE_DETAILS"] = {}
if instance_data["STORAGE_TYPE"] == "MongoDB": if instance_data["STORAGE_TYPE"] == "MongoDB":
if confirm("Would you like to import your data? (y/n) "): if confirm("Would you like to import your data? (y/n) "):
await mongo_to_json(current_data_dir, storage_details) await mongo_to_json(current_data_dir, storage_details)
elif instance_data["STORAGE_TYPE"] == "MongoDBV2":
raise NotImplementedError(
"We cannot convert from this version of MongoDB to JSON at this time."
)
if name != selected: if name != selected:
save_config(selected, {}, remove=True) save_config(selected, {}, remove=True)