mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-08 20:28:55 -05:00
Only initialize and teardown driver if actually needed (#5313)
* Fix #5312 * Update setup.py * put db actions under one if statement * check backend type and improve displayed message * accept format fix Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * fix whitespace Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * separate datapath delete from data delete * Fix indentation * Call `driver_cls.initialize()` outside try-finally * Backup requires db server to run too + some simplifications Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
parent
d69326b1fe
commit
2ce8e65527
@ -248,39 +248,41 @@ async def remove_instance(
|
|||||||
remove_datapath: Optional[bool] = None,
|
remove_datapath: Optional[bool] = None,
|
||||||
):
|
):
|
||||||
data_manager.load_basic_configuration(instance)
|
data_manager.load_basic_configuration(instance)
|
||||||
|
backend = get_current_backend(instance)
|
||||||
|
|
||||||
if interactive is True and delete_data is None:
|
if interactive is True and delete_data is None:
|
||||||
delete_data = click.confirm(
|
msg = "Would you like to delete this instance's data?"
|
||||||
"Would you like to delete this instance's data?", default=False
|
if backend != BackendType.JSON:
|
||||||
)
|
msg += " The database server must be running for this to work."
|
||||||
|
delete_data = click.confirm(msg, default=False)
|
||||||
|
|
||||||
if interactive is True and _create_backup is None:
|
if interactive is True and _create_backup is None:
|
||||||
_create_backup = click.confirm(
|
msg = "Would you like to make a backup of the data for this instance?"
|
||||||
"Would you like to make a backup of the data for this instance?", default=False
|
if backend != BackendType.JSON:
|
||||||
)
|
msg += " The database server must be running for this to work."
|
||||||
|
_create_backup = click.confirm(msg, default=False)
|
||||||
|
|
||||||
if _create_backup is True:
|
if _create_backup is True:
|
||||||
await create_backup(instance)
|
await create_backup(instance)
|
||||||
|
|
||||||
backend = get_current_backend(instance)
|
|
||||||
driver_cls = drivers.get_driver_class(backend)
|
driver_cls = drivers.get_driver_class(backend)
|
||||||
await driver_cls.initialize(**data_manager.storage_details())
|
if delete_data is True:
|
||||||
try:
|
await driver_cls.initialize(**data_manager.storage_details())
|
||||||
if delete_data is True:
|
try:
|
||||||
await driver_cls.delete_all_data(interactive=interactive, drop_db=drop_db)
|
await driver_cls.delete_all_data(interactive=interactive, drop_db=drop_db)
|
||||||
|
finally:
|
||||||
|
await driver_cls.teardown()
|
||||||
|
|
||||||
if interactive is True and remove_datapath is None:
|
if interactive is True and remove_datapath is None:
|
||||||
remove_datapath = click.confirm(
|
remove_datapath = click.confirm(
|
||||||
"Would you like to delete the instance's entire datapath?", default=False
|
"Would you like to delete the instance's entire datapath?", default=False
|
||||||
)
|
)
|
||||||
|
|
||||||
if remove_datapath is True:
|
if remove_datapath is True:
|
||||||
data_path = data_manager.core_data_path().parent
|
data_path = data_manager.core_data_path().parent
|
||||||
safe_delete(data_path)
|
safe_delete(data_path)
|
||||||
|
|
||||||
save_config(instance, {}, remove=True)
|
save_config(instance, {}, remove=True)
|
||||||
finally:
|
|
||||||
await driver_cls.teardown()
|
|
||||||
print("The instance {} has been removed\n".format(instance))
|
print("The instance {} has been removed\n".format(instance))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user