From c82ac5ae689f5134270eab71e53c2ec06dc6c9ae Mon Sep 17 00:00:00 2001 From: Will Date: Wed, 10 Apr 2019 20:42:28 -0400 Subject: [PATCH] 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 --- redbot/core/drivers/__init__.py | 7 ++++++- redbot/setup.py | 12 ++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/redbot/core/drivers/__init__.py b/redbot/core/drivers/__init__.py index 2809427d9..a3f3c7d56 100644 --- a/redbot/core/drivers/__init__.py +++ b/redbot/core/drivers/__init__.py @@ -28,8 +28,13 @@ def get_driver(type, *args, **kwargs): from .red_json import JSON return JSON(*args, **kwargs) - elif type == "MongoDB": + elif type == "MongoDBV2": from .red_mongo import Mongo 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)) diff --git a/redbot/setup.py b/redbot/setup.py index 00a93f8a3..e55aa3660 100644 --- a/redbot/setup.py +++ b/redbot/setup.py @@ -114,7 +114,7 @@ def get_storage_type(): print() print("Please choose your storage backend (if you're unsure, choose 1).") print("1. JSON (file storage, requires no database).") - print("2. MongoDB (not recommended, currently unstable)") + print("2. MongoDB") storage = input("> ") try: storage = int(storage) @@ -260,9 +260,9 @@ async def edit_instance(): if confirm("Would you like to change the storage type? (y/n):"): storage = get_storage_type() - storage_dict = {1: "JSON", 2: "MongoDB"} + storage_dict = {1: "JSON", 2: "MongoDBV2"} 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 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.") # if confirm("Would you like to import your data? (y/n) "): # await json_to_mongo(current_data_dir, storage_details) - else: + elif storage_dict.get(storage, 1) == "JSON": storage_details = instance_data["STORAGE_DETAILS"] default_dirs["STORAGE_DETAILS"] = {} if instance_data["STORAGE_TYPE"] == "MongoDB": if confirm("Would you like to import your data? (y/n) "): 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: save_config(selected, {}, remove=True)