odoo-openupgrade-wizard/odoo_openupgrade_wizard/tools/tools_click_odoo_contrib.py
Sylvain LE GAL 7a31cc666d [FIX] copydb : add the copy of the filestore
[DOC] Add documentation section for the copydb function
2023-07-17 14:12:14 +02:00

30 lines
853 B
Python

import shutil
from loguru import logger
from odoo_openupgrade_wizard.tools.tools_postgres import (
ensure_database,
execute_sql_request,
)
def copydb(ctx, source, dest):
# drop database if exist
ensure_database(ctx, dest, state="absent")
# Copy database
logger.info(f"Copy database {source} into {dest} ...")
request = f"CREATE DATABASE {dest} WITH TEMPLATE {source};"
execute_sql_request(ctx, request)
main_path = ctx.obj["filestore_folder_path"] / "filestore"
source_path = main_path / source
dest_path = main_path / dest
# Drop filestore if exist
logger.info(f"Remove filestore of '{dest}' if exists.")
shutil.rmtree(dest_path, ignore_errors=True)
# Copy Filestore
logger.info(f"Copy filestore of '{source}' into '{dest}' folder ...")
shutil.copytree(source_path, dest_path)