From 9008410fa4c6e39c1f2fc2c5824c9f81b949d0d3 Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Mon, 5 Apr 2021 21:17:18 +0200 Subject: [PATCH] Fix dropping db in `redbot-setup delete` (#3833) * Fix dropping db in `redbot-setup delete` * fix docstrings --- redbot/core/drivers/_mongo.py | 2 +- redbot/core/drivers/postgres/postgres.py | 46 ++++++++---------------- 2 files changed, 15 insertions(+), 33 deletions(-) diff --git a/redbot/core/drivers/_mongo.py b/redbot/core/drivers/_mongo.py index 58704ddd5..a628c1669 100644 --- a/redbot/core/drivers/_mongo.py +++ b/redbot/core/drivers/_mongo.py @@ -381,7 +381,7 @@ class MongoDriver(BaseDriver): while True: resp = input("> ") try: - drop_db = bool(options.index(resp)) + drop_db = not bool(options.index(resp)) except ValueError: print("Please type a number corresponding to one of the options.") else: diff --git a/redbot/core/drivers/postgres/postgres.py b/redbot/core/drivers/postgres/postgres.py index 46af7b12f..2b00e0cf2 100644 --- a/redbot/core/drivers/postgres/postgres.py +++ b/redbot/core/drivers/postgres/postgres.py @@ -204,46 +204,28 @@ class PostgresDriver(BaseDriver): yield row["cog_name"], row["cog_id"] @classmethod - async def delete_all_data( - cls, *, interactive: bool = False, drop_db: Optional[bool] = None, **kwargs - ) -> None: + async def delete_all_data(cls, *, drop_db: Optional[bool] = None, **kwargs) -> None: """Delete all data being stored by this driver. + Schemas within the database which + store bot data will be dropped, as well as functions, + aggregates, event triggers, and meta-tables. + Parameters ---------- - interactive : bool - Set to ``True`` to allow the method to ask the user for - input from the console, regarding the other unset parameters - for this method. drop_db : Optional[bool] - Set to ``True`` to drop the entire database for the current - bot's instance. Otherwise, schemas within the database which - store bot data will be dropped, as well as functions, - aggregates, event triggers, and meta-tables. + If set to ``True``, function will print information + about not being able to drop the entire database. """ - if interactive is True and drop_db is None: - print( - "Please choose from one of the following options:\n" - " 1. Drop the entire PostgreSQL database for this instance, or\n" - " 2. Delete all of Red's data within this database, without dropping the database " - "itself." - ) - options = ("1", "2") - while True: - resp = input("> ") - try: - drop_db = bool(options.index(resp)) - except ValueError: - print("Please type a number corresponding to one of the options.") - else: - break if drop_db is True: - storage_details = data_manager.storage_details() - await cls._pool.execute(f"DROP DATABASE $1", storage_details["database"]) - else: - with DROP_DDL_SCRIPT_PATH.open() as fs: - await cls._pool.execute(fs.read()) + print( + "Dropping the entire database is not possible in PostgreSQL driver." + " We will delete all of Red's data within this database," + " without dropping the database itself." + ) + with DROP_DDL_SCRIPT_PATH.open() as fs: + await cls._pool.execute(fs.read()) @classmethod async def _execute(cls, query: str, *args, method: Optional[Callable] = None) -> Any: