[IMP] todo: add erase-database menu command
Give users a guided, confirmation-gated way to drop one or all databases from the interactive CLI. Previously this meant running make db_drop_all or odoo_bin db --drop by hand, which is easy to mistype and offers no safeguard. The new entry requires an explicit 'oui'/'yes' (default no) before any irreversible deletion. Generated by Claude Code 2.1.191 claude-sonnet-4-6 Co-Authored-By: Mathieu Benoit <mathben@technolibre.ca>
This commit is contained in:
parent
7c99ce9f29
commit
eb64155f3c
3 changed files with 113 additions and 0 deletions
|
|
@ -54,6 +54,70 @@ class DatabaseManager:
|
|||
else:
|
||||
print(t("cmd_not_found"))
|
||||
|
||||
def _confirm_drop(self, message: str) -> bool:
|
||||
"""Ask for an explicit 'oui'/'yes' confirmation, default is no."""
|
||||
print(f"⚠️ {message}")
|
||||
answer = (
|
||||
input(t("Type 'oui' to confirm (default: no): ")).strip().lower()
|
||||
)
|
||||
return answer in ("oui", "yes")
|
||||
|
||||
def drop_database(self) -> None:
|
||||
print(f"⚠️ {t('Erase a database — irreversible operation!')}")
|
||||
choices = [
|
||||
{
|
||||
"prompt_description": t(
|
||||
"Erase ALL databases (make db_drop_all)"
|
||||
)
|
||||
},
|
||||
{"prompt_description": t("Erase a single database")},
|
||||
]
|
||||
help_info = self._fill_help_info(choices)
|
||||
|
||||
while True:
|
||||
status = click.prompt(help_info)
|
||||
print()
|
||||
if status == "0":
|
||||
return
|
||||
elif status == "1":
|
||||
self._drop_all_databases()
|
||||
return
|
||||
elif status == "2":
|
||||
self._drop_single_database()
|
||||
return
|
||||
else:
|
||||
print(t("Command not found !"))
|
||||
|
||||
def _drop_all_databases(self) -> None:
|
||||
if not self._confirm_drop(
|
||||
t("You are about to erase ALL databases. This cannot be undone.")
|
||||
):
|
||||
print(t("Database deletion cancelled."))
|
||||
return
|
||||
self._execute.exec_command_live(
|
||||
"make db_drop_all",
|
||||
source_erplibre=False,
|
||||
single_source_erplibre=True,
|
||||
)
|
||||
|
||||
def _drop_single_database(self) -> None:
|
||||
database_name = self.select_database()
|
||||
if not database_name:
|
||||
print(t("No database selected."))
|
||||
return
|
||||
message = t(
|
||||
"You are about to erase the database '{database}'."
|
||||
" This cannot be undone."
|
||||
).format(database=database_name)
|
||||
if not self._confirm_drop(message):
|
||||
print(t("Database deletion cancelled."))
|
||||
return
|
||||
self._execute.exec_command_live(
|
||||
f"./odoo_bin.sh db --drop --database {database_name}",
|
||||
source_erplibre=False,
|
||||
single_source_erplibre=True,
|
||||
)
|
||||
|
||||
def restore_from_database(self, show_remote_list: bool = True) -> None:
|
||||
path_image_db = os.path.join(os.getcwd(), "image_db")
|
||||
print("[1] By filename from image_db")
|
||||
|
|
|
|||
|
|
@ -1479,6 +1479,7 @@ class TODO:
|
|||
},
|
||||
{"prompt_description": t("Restore from backup (.zip)")},
|
||||
{"prompt_description": t("Create backup (.zip)")},
|
||||
{"prompt_description": t("Erase a database")},
|
||||
]
|
||||
help_info = self.fill_help_info(choices)
|
||||
|
||||
|
|
@ -1493,6 +1494,8 @@ class TODO:
|
|||
self.db_manager.restore_from_database()
|
||||
elif status == "3":
|
||||
self.db_manager.create_backup_from_database()
|
||||
elif status == "4":
|
||||
self.db_manager.drop_database()
|
||||
else:
|
||||
print(t("Command not found !"))
|
||||
|
||||
|
|
|
|||
|
|
@ -299,6 +299,52 @@ TRANSLATIONS = {
|
|||
"fr": "Faites des modifications sur les bases de données!",
|
||||
"en": "Make changes to databases!",
|
||||
},
|
||||
# Database drop / erase
|
||||
"Erase a database": {
|
||||
"fr": "Effacer une base de données",
|
||||
"en": "Erase a database",
|
||||
},
|
||||
"Erase a database — irreversible operation!": {
|
||||
"fr": "Effacer une base de données — opération irréversible !",
|
||||
"en": "Erase a database — irreversible operation!",
|
||||
},
|
||||
"Erase ALL databases (make db_drop_all)": {
|
||||
"fr": "Effacer TOUTES les bases de données (make db_drop_all)",
|
||||
"en": "Erase ALL databases (make db_drop_all)",
|
||||
},
|
||||
"Erase a single database": {
|
||||
"fr": "Effacer une seule base de données",
|
||||
"en": "Erase a single database",
|
||||
},
|
||||
"You are about to erase ALL databases. This cannot be undone.": {
|
||||
"fr": (
|
||||
"Tu es sur le point d'effacer TOUTES les bases de données."
|
||||
" C'est irréversible."
|
||||
),
|
||||
"en": "You are about to erase ALL databases. This cannot be undone.",
|
||||
},
|
||||
"You are about to erase the database '{database}'. This cannot be undone.": {
|
||||
"fr": (
|
||||
"Tu es sur le point d'effacer la base de données « {database} »."
|
||||
" C'est irréversible."
|
||||
),
|
||||
"en": (
|
||||
"You are about to erase the database '{database}'."
|
||||
" This cannot be undone."
|
||||
),
|
||||
},
|
||||
"Type 'oui' to confirm (default: no): ": {
|
||||
"fr": "Tape « oui » pour confirmer (défaut : non) : ",
|
||||
"en": "Type 'oui'/'yes' to confirm (default: no): ",
|
||||
},
|
||||
"Database deletion cancelled.": {
|
||||
"fr": "Effacement de la base de données annulé.",
|
||||
"en": "Database deletion cancelled.",
|
||||
},
|
||||
"No database selected.": {
|
||||
"fr": "Aucune base de données sélectionnée.",
|
||||
"en": "No database selected.",
|
||||
},
|
||||
"Manage execution processes!": {
|
||||
"fr": "Manipuler les processus d'exécution!",
|
||||
"en": "Manage execution processes!",
|
||||
|
|
|
|||
Loading…
Reference in a new issue