mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
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:
parent
b8cbaa2fa0
commit
7e9b1b87e6
1
changelog.d/2962.enhance.rst
Normal file
1
changelog.d/2962.enhance.rst
Normal file
@ -0,0 +1 @@
|
||||
```redbot-setup delete`` now has the option to leave Red's data untouched on database backends.
|
||||
@ -301,12 +301,18 @@ async def create_backup(instance: str) -> None:
|
||||
async def remove_instance(
|
||||
instance,
|
||||
interactive: bool = False,
|
||||
delete_data: Optional[bool] = None,
|
||||
_create_backup: Optional[bool] = None,
|
||||
drop_db: Optional[bool] = None,
|
||||
remove_datapath: Optional[bool] = None,
|
||||
):
|
||||
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:
|
||||
_create_backup = click.confirm(
|
||||
"Would you like to make a backup of the data for this instance?", default=False
|
||||
@ -321,7 +327,8 @@ async def remove_instance(
|
||||
else:
|
||||
driver_cls = drivers.get_driver_class(backend)
|
||||
|
||||
await driver_cls.delete_all_data(interactive=interactive, drop_db=drop_db)
|
||||
if delete_data is True:
|
||||
await driver_cls.delete_all_data(interactive=interactive, drop_db=drop_db)
|
||||
|
||||
if interactive is True and remove_datapath is None:
|
||||
remove_datapath = click.confirm(
|
||||
@ -376,6 +383,16 @@ def cli(ctx, debug):
|
||||
default=True,
|
||||
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(
|
||||
"--backup/--no-backup",
|
||||
"_create_backup",
|
||||
@ -392,7 +409,8 @@ def cli(ctx, debug):
|
||||
default=None,
|
||||
help=(
|
||||
"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(
|
||||
@ -401,19 +419,23 @@ def cli(ctx, debug):
|
||||
default=None,
|
||||
help=(
|
||||
"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(
|
||||
instance: str,
|
||||
interactive: bool,
|
||||
delete_data: Optional[bool],
|
||||
_create_backup: Optional[bool],
|
||||
drop_db: Optional[bool],
|
||||
remove_datapath: Optional[bool],
|
||||
):
|
||||
loop = asyncio.get_event_loop()
|
||||
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
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user