[ADD] restore-sql

This commit is contained in:
Gabriel Pickenhayn 2024-05-07 14:48:44 +00:00 committed by Rémy Taymans
parent 1498148d65
commit 7dcf456525
3 changed files with 21 additions and 12 deletions

View File

@ -0,0 +1 @@
Add option ``p`` (SQL format) allowing use from ``--database-format`` CLI. This allows you to restore database in SQL format (used by odoo full backup)

View File

@ -18,11 +18,11 @@ from odoo_openupgrade_wizard.tools.tools_system import restore_filestore
@click.option(
"--database-format",
required=True,
type=click.Choice(("c", "d", "t")),
type=click.Choice(("c", "d", "t", "p")),
default="c",
help="Database format (see pg_dump options): "
"custom format compressed (c), directory (d), tar file (t)."
"plain sql text (p) is not implemented",
"custom format compressed (c), directory (d), tar file (t),"
" plain sql text (p).",
)
@click.option(
"--filestore-path",

View File

@ -250,15 +250,23 @@ def execute_pg_restore(
container = get_postgres_container(ctx)
ensure_database(ctx, database, "absent")
ensure_database(ctx, database, "present")
command = (
"pg_restore"
f" {Path('/env') / filepath}"
f" --dbname={database}"
" --schema=public"
" --username=odoo"
" --no-owner"
f" --format {database_format}"
)
if database_format == "p":
command = (
"psql"
f" --file='{Path('/env') / filepath}'"
" --username odoo"
f" --dbname={database}"
)
else:
command = (
"pg_restore"
f" {Path('/env') / filepath}"
f" --dbname={database}"
" --schema=public"
" --username=odoo"
" --no-owner"
f" --format {database_format}"
)
logger.info(f"Restoring database '{database}'...")
pg_dump_result = exec_container(container, command)
return pg_dump_result.output.decode("utf8")