Allow keeping data in redbot-setup delete (#2965)

* Allow keeping data in `redbot-setup delete`

Signed-off-by: Toby Harradine <tobyharradine@gmail.com>

* Add changelog entry

Signed-off-by: Toby Harradine <tobyharradine@gmail.com>
This commit is contained in:
Toby Harradine 2019-11-07 04:24:54 +11:00 committed by Michael H
parent b8cbaa2fa0
commit 7e9b1b87e6
2 changed files with 27 additions and 4 deletions

View File

@ -0,0 +1 @@
```redbot-setup delete`` now has the option to leave Red's data untouched on database backends.

View File

@ -301,12 +301,18 @@ async def create_backup(instance: str) -> None:
async def remove_instance( async def remove_instance(
instance, instance,
interactive: bool = False, interactive: bool = False,
delete_data: Optional[bool] = None,
_create_backup: Optional[bool] = None, _create_backup: Optional[bool] = None,
drop_db: Optional[bool] = None, drop_db: Optional[bool] = None,
remove_datapath: Optional[bool] = None, remove_datapath: Optional[bool] = None,
): ):
data_manager.load_basic_configuration(instance) data_manager.load_basic_configuration(instance)
if interactive is True and delete_data is None:
delete_data = click.confirm(
"Would you like to delete this instance's data?", default=False
)
if interactive is True and _create_backup is None: if interactive is True and _create_backup is None:
_create_backup = click.confirm( _create_backup = click.confirm(
"Would you like to make a backup of the data for this instance?", default=False "Would you like to make a backup of the data for this instance?", default=False
@ -321,6 +327,7 @@ async def remove_instance(
else: else:
driver_cls = drivers.get_driver_class(backend) driver_cls = drivers.get_driver_class(backend)
if delete_data is True:
await driver_cls.delete_all_data(interactive=interactive, drop_db=drop_db) await driver_cls.delete_all_data(interactive=interactive, drop_db=drop_db)
if interactive is True and remove_datapath is None: if interactive is True and remove_datapath is None:
@ -376,6 +383,16 @@ def cli(ctx, debug):
default=True, default=True,
help="Don't ask for user input during the process.", help="Don't ask for user input during the process.",
) )
@click.option(
"--delete-data/--no-delete-data",
"delete_data",
is_flag=True,
default=None,
help=(
"Delete this instance's data. "
"If these options and --no-prompt are omitted, you will be asked about this."
),
)
@click.option( @click.option(
"--backup/--no-backup", "--backup/--no-backup",
"_create_backup", "_create_backup",
@ -392,7 +409,8 @@ def cli(ctx, debug):
default=None, default=None,
help=( help=(
"Drop the entire database constaining this instance's data. Has no effect on JSON " "Drop the entire database constaining this instance's data. Has no effect on JSON "
"instances. If these options and --no-prompt are omitted, you will be asked about this." "instances, or if --no-delete-data is set. If these options and --no-prompt are omitted,"
"you will be asked about this."
), ),
) )
@click.option( @click.option(
@ -401,19 +419,23 @@ def cli(ctx, debug):
default=None, default=None,
help=( help=(
"Remove this entire instance's datapath. If these options and --no-prompt are omitted, " "Remove this entire instance's datapath. If these options and --no-prompt are omitted, "
"you will be asked about this." "you will be asked about this. NOTE: --remove-datapath will override --no-delete-data "
"for JSON instances."
), ),
) )
def delete( def delete(
instance: str, instance: str,
interactive: bool, interactive: bool,
delete_data: Optional[bool],
_create_backup: Optional[bool], _create_backup: Optional[bool],
drop_db: Optional[bool], drop_db: Optional[bool],
remove_datapath: Optional[bool], remove_datapath: Optional[bool],
): ):
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
loop.run_until_complete( loop.run_until_complete(
remove_instance(instance, interactive, _create_backup, drop_db, remove_datapath) remove_instance(
instance, interactive, delete_data, _create_backup, drop_db, remove_datapath
)
) )