Fix dropping db in redbot-setup delete (#3833)

* Fix dropping db in `redbot-setup delete`

* fix docstrings
This commit is contained in:
jack1142 2021-04-05 21:17:18 +02:00 committed by GitHub
parent b7d8b0552e
commit 9008410fa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 33 deletions

View File

@ -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:

View File

@ -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: