Merge branch 'imp-restoredb' into 'main'
[IMP] cli restoredb: manage filstore in subfolder Closes #63 See merge request odoo-openupgrade-wizard/odoo-openupgrade-wizard!109
This commit is contained in:
commit
b4632f938b
1
newsfragments/+63.bugfix
Normal file
1
newsfragments/+63.bugfix
Normal file
|
|
@ -0,0 +1 @@
|
|||
Handles the case where the filestore data provided in the source is in a "filestore" subfolder
|
||||
|
|
@ -0,0 +1 @@
|
|||
restoredb: Use builtins click feature to check if provided paths exist
|
||||
|
|
@ -12,7 +12,7 @@ from odoo_openupgrade_wizard.tools.tools_system import restore_filestore
|
|||
@click.option(
|
||||
"--database-path",
|
||||
required=True,
|
||||
type=click.Path(readable=True, resolve_path=True),
|
||||
type=click.Path(readable=True, resolve_path=True, exists=True),
|
||||
help="Path to the database dump relative project folder.",
|
||||
)
|
||||
@click.option(
|
||||
|
|
@ -27,7 +27,7 @@ from odoo_openupgrade_wizard.tools.tools_system import restore_filestore
|
|||
@click.option(
|
||||
"--filestore-path",
|
||||
required=True,
|
||||
type=click.Path(readable=True, resolve_path=True),
|
||||
type=click.Path(readable=True, resolve_path=True, exists=True),
|
||||
help="Path to the filestore backup.",
|
||||
)
|
||||
@click.option(
|
||||
|
|
@ -59,6 +59,7 @@ def restoredb(
|
|||
"database-path should be inside the project path to allow "
|
||||
"postgresql to read to it."
|
||||
)
|
||||
|
||||
# Restore the database
|
||||
output = execute_pg_restore(
|
||||
ctx,
|
||||
|
|
|
|||
|
|
@ -173,3 +173,12 @@ def restore_filestore(
|
|||
else: # works for "t" and "tgz"
|
||||
tar = tarfile.open(src_path)
|
||||
tar.extractall(path=filestore_path)
|
||||
|
||||
# If a filestore/filestore/database/filestore directory exists,
|
||||
# it means that the filestore was in a "filestore" subdirectory
|
||||
# and we need to move this content to the parent directory.
|
||||
filestore_subfolder = filestore_path / "filestore"
|
||||
if filestore_subfolder.exists():
|
||||
for file in filestore_subfolder.iterdir():
|
||||
shutil.move(file, filestore_path)
|
||||
shutil.rmtree(filestore_subfolder)
|
||||
|
|
|
|||
|
|
@ -45,6 +45,38 @@ def test_cli_restoredb(mocker):
|
|||
# check filestore exists
|
||||
assert dest_filestore_path.exists()
|
||||
|
||||
# check the filestore content is at the right place
|
||||
assert (dest_filestore_path / "01").exists()
|
||||
|
||||
# Check database exists
|
||||
assert_database(ctx, db_name, "present")
|
||||
|
||||
# Delete filestore and database
|
||||
shutil.rmtree(dest_filestore_path)
|
||||
ensure_database(ctx, db_name, state="absent")
|
||||
|
||||
shutil.copyfile(
|
||||
pathlib.Path("../restoredb/test_with_nested_filestore_dir.tar.gz"),
|
||||
filestore_path,
|
||||
)
|
||||
|
||||
cli_runner_invoke(
|
||||
[
|
||||
"restoredb",
|
||||
f"--database={db_name}",
|
||||
f"--database-path={database_path}",
|
||||
"--database-format=c",
|
||||
f"--filestore-path={filestore_path}",
|
||||
"--filestore-format=tgz",
|
||||
],
|
||||
)
|
||||
|
||||
# check filestore exists
|
||||
assert dest_filestore_path.exists()
|
||||
|
||||
# check the filestore content is at the right place
|
||||
assert (dest_filestore_path / "01").exists()
|
||||
|
||||
# Check database exists
|
||||
assert_database(ctx, db_name, "present")
|
||||
|
||||
|
|
|
|||
Binary file not shown.
BIN
tests/data/restoredb/test_with_nested_filestore_dir.tar.gz
Normal file
BIN
tests/data/restoredb/test_with_nested_filestore_dir.tar.gz
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user