mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
Fix dropping db in redbot-setup delete (#3833)
* Fix dropping db in `redbot-setup delete` * fix docstrings
This commit is contained in:
parent
b7d8b0552e
commit
9008410fa4
@ -381,7 +381,7 @@ class MongoDriver(BaseDriver):
|
|||||||
while True:
|
while True:
|
||||||
resp = input("> ")
|
resp = input("> ")
|
||||||
try:
|
try:
|
||||||
drop_db = bool(options.index(resp))
|
drop_db = not bool(options.index(resp))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print("Please type a number corresponding to one of the options.")
|
print("Please type a number corresponding to one of the options.")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -204,46 +204,28 @@ class PostgresDriver(BaseDriver):
|
|||||||
yield row["cog_name"], row["cog_id"]
|
yield row["cog_name"], row["cog_id"]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def delete_all_data(
|
async def delete_all_data(cls, *, drop_db: Optional[bool] = None, **kwargs) -> None:
|
||||||
cls, *, interactive: bool = False, drop_db: Optional[bool] = None, **kwargs
|
|
||||||
) -> None:
|
|
||||||
"""Delete all data being stored by this driver.
|
"""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
|
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]
|
drop_db : Optional[bool]
|
||||||
Set to ``True`` to drop the entire database for the current
|
If set to ``True``, function will print information
|
||||||
bot's instance. Otherwise, schemas within the database which
|
about not being able to drop the entire database.
|
||||||
store bot data will be dropped, as well as functions,
|
|
||||||
aggregates, event triggers, and meta-tables.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
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:
|
if drop_db is True:
|
||||||
storage_details = data_manager.storage_details()
|
print(
|
||||||
await cls._pool.execute(f"DROP DATABASE $1", storage_details["database"])
|
"Dropping the entire database is not possible in PostgreSQL driver."
|
||||||
else:
|
" We will delete all of Red's data within this database,"
|
||||||
with DROP_DDL_SCRIPT_PATH.open() as fs:
|
" without dropping the database itself."
|
||||||
await cls._pool.execute(fs.read())
|
)
|
||||||
|
with DROP_DDL_SCRIPT_PATH.open() as fs:
|
||||||
|
await cls._pool.execute(fs.read())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def _execute(cls, query: str, *args, method: Optional[Callable] = None) -> Any:
|
async def _execute(cls, query: str, *args, method: Optional[Callable] = None) -> Any:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user