[ADD][WIP] copydb (pseudo click-odoo function

This commit is contained in:
Sylvain LE GAL 2022-07-15 01:31:47 +02:00
parent bdc9b606ec
commit e63851cf9e
4 changed files with 43 additions and 1 deletions

View File

@ -29,8 +29,9 @@ and provides helpers to run (and replay) migrations until it works.
**Prerequites:**
* The tools run on debian system
* You should have docker installed on your system
* the tools run on debian system
* Some features require extra packages. To have all the features available run:
**Installation:**

View File

@ -9,6 +9,7 @@ from click_loglevel import LogLevel
from loguru import logger
import odoo_openupgrade_wizard
from odoo_openupgrade_wizard.cli.cli_copydb import copydb
from odoo_openupgrade_wizard.cli.cli_docker_build import docker_build
from odoo_openupgrade_wizard.cli.cli_estimate_workload import estimate_workload
from odoo_openupgrade_wizard.cli.cli_execute_script_python import (
@ -103,6 +104,7 @@ def main(ctx, env_folder, filestore_folder, log_level):
raise
main.add_command(copydb)
main.add_command(docker_build)
main.add_command(estimate_workload)
main.add_command(execute_script_python)

View File

@ -0,0 +1,26 @@
import click
from odoo_openupgrade_wizard.tools import (
tools_click_odoo_contrib as click_odoo_contrib,
)
@click.command()
@click.option(
"-s",
"--source",
type=str,
help="Name of the database to copy",
)
@click.option(
"-d",
"--dest",
type=str,
help="Name of the new database",
)
@click.pass_context
def copydb(ctx, source, dest):
"""Create an Odoo database by copying an existing one.
it will copy the postgres database and the filestore.
"""
click_odoo_contrib.copydb(ctx, source, dest)

View File

@ -0,0 +1,13 @@
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
request = f"CREATE DATABASE {dest} WITH TEMPLATE {source};"
execute_sql_request(ctx, request)