Skip to content

Commit

Permalink
Fix dropping db in redbot-setup delete (#3833)
Browse files Browse the repository at this point in the history
* Fix dropping db in `redbot-setup delete`

* fix docstrings
  • Loading branch information
Jackenmen committed Apr 5, 2021
1 parent b7d8b05 commit 9008410
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 32 deletions.
2 changes: 1 addition & 1 deletion redbot/core/drivers/_mongo.py
Expand Up @@ -381,7 +381,7 @@ async def delete_all_data(
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:
Expand Down
44 changes: 13 additions & 31 deletions redbot/core/drivers/postgres/postgres.py
Expand Up @@ -204,46 +204,28 @@ async def aiter_cogs(cls) -> AsyncIterator[Tuple[str, str]]:
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:
if drop_db is True:
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."
"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."
)
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())
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:
Expand Down

0 comments on commit 9008410

Please sign in to comment.