WIp
This commit is contained in:
parent
5d6905ebaa
commit
ffa406ef20
|
|
@ -44,4 +44,5 @@ pytest:
|
|||
# Create a postgresql container
|
||||
- docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo -e POSTGRES_DB=postgres --publish 9542:5432 --name db postgres:13
|
||||
|
||||
- poetry run pytest --cov odoo_openupgrade_wizard -v
|
||||
- poetry run pytest --cov odoo_openupgrade_wizard -v\
|
||||
tests/cli_A_init_test.py
|
||||
|
|
|
|||
|
|
@ -10,7 +10,10 @@ from loguru import logger
|
|||
|
||||
import odoo_openupgrade_wizard
|
||||
from odoo_openupgrade_wizard.cli_docker_build import docker_build
|
||||
from odoo_openupgrade_wizard.cli_execute_script import execute_script
|
||||
from odoo_openupgrade_wizard.cli_execute_script_python import (
|
||||
execute_script_python,
|
||||
)
|
||||
from odoo_openupgrade_wizard.cli_execute_script_sql import execute_script_sql
|
||||
from odoo_openupgrade_wizard.cli_get_code import get_code
|
||||
from odoo_openupgrade_wizard.cli_init import init
|
||||
from odoo_openupgrade_wizard.cli_install_from_csv import install_from_csv
|
||||
|
|
@ -109,5 +112,6 @@ main.add_command(docker_build)
|
|||
main.add_command(run)
|
||||
main.add_command(install_from_csv)
|
||||
main.add_command(upgrade)
|
||||
main.add_command(execute_script)
|
||||
main.add_command(execute_script_python)
|
||||
main.add_command(execute_script_sql)
|
||||
main.add_command(test_dev)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ from odoo_openupgrade_wizard.tools_odoo import (
|
|||
" scripts placed in the migration step folder.",
|
||||
)
|
||||
@click.pass_context
|
||||
def execute_script(ctx, step, database, script_file_path):
|
||||
def execute_script_python(ctx, step, database, script_file_path):
|
||||
migration_step = get_migration_step_from_options(ctx, step)
|
||||
|
||||
execute_python_files_post_migration(
|
||||
35
odoo_openupgrade_wizard/cli_execute_script_sql.py
Normal file
35
odoo_openupgrade_wizard/cli_execute_script_sql.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from odoo_openupgrade_wizard.cli_options import (
|
||||
database_option_required,
|
||||
get_migration_step_from_options,
|
||||
step_option,
|
||||
)
|
||||
from odoo_openupgrade_wizard.tools_postgres import (
|
||||
execute_sql_files_pre_migration,
|
||||
)
|
||||
|
||||
|
||||
@click.command()
|
||||
@step_option
|
||||
@database_option_required
|
||||
@click.option(
|
||||
"--script-file-path",
|
||||
multiple=True,
|
||||
type=click.Path(
|
||||
exists=True,
|
||||
dir_okay=False,
|
||||
resolve_path=True,
|
||||
),
|
||||
help="List of SQL files that will be executed, replacing the default"
|
||||
" scripts placed in the migration step folder.",
|
||||
)
|
||||
@click.pass_context
|
||||
def execute_script_sql(ctx, step, database, script_file_path):
|
||||
migration_step = get_migration_step_from_options(ctx, step)
|
||||
|
||||
execute_sql_files_pre_migration(
|
||||
ctx, database, migration_step, [Path(x) for x in script_file_path]
|
||||
)
|
||||
|
|
@ -16,6 +16,7 @@ from odoo_openupgrade_wizard.configuration_version_dependant import (
|
|||
)
|
||||
from odoo_openupgrade_wizard.tools_docker import kill_container, run_container
|
||||
from odoo_openupgrade_wizard.tools_odoo_instance import OdooInstance
|
||||
from odoo_openupgrade_wizard.tools_system import get_script_folder
|
||||
|
||||
|
||||
def get_odoo_addons_path(ctx, root_path: Path, migration_step: dict) -> str:
|
||||
|
|
@ -43,10 +44,6 @@ def get_odoo_addons_path(ctx, root_path: Path, migration_step: dict) -> str:
|
|||
return ",".join([str(x) for x in addons_path])
|
||||
|
||||
|
||||
def get_script_folder(ctx, migration_step: dict) -> Path:
|
||||
return ctx.obj["script_folder_path"] / migration_step["complete_name"]
|
||||
|
||||
|
||||
def get_odoo_env_path(ctx, odoo_version: dict) -> Path:
|
||||
folder_name = "env_%s" % str(odoo_version["release"]).rjust(4, "0")
|
||||
return ctx.obj["src_folder_path"] / folder_name
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from odoo_openupgrade_wizard.tools_docker import get_docker_client
|
||||
from odoo_openupgrade_wizard.tools_system import get_script_folder
|
||||
|
||||
|
||||
def get_postgres_container():
|
||||
|
|
@ -63,3 +67,18 @@ def ensure_database(database: str, state="present"):
|
|||
logger.info("Drop database '%s' ..." % database)
|
||||
request = "DROP DATABASE {database};".format(database=database)
|
||||
execute_sql_request(request)
|
||||
|
||||
|
||||
def execute_sql_files_pre_migration(
|
||||
ctx, database: str, migration_step: dict, sql_files: list = []
|
||||
):
|
||||
if not sql_files:
|
||||
script_folder = get_script_folder(ctx, migration_step)
|
||||
|
||||
sql_files = [
|
||||
script_folder / Path(f)
|
||||
for f in os.listdir(script_folder)
|
||||
if os.path.isfile(os.path.join(script_folder, f))
|
||||
and f[-3:] == ".sql"
|
||||
]
|
||||
sql_files = sorted(sql_files)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@ from plumbum.cmd import mkdir
|
|||
from odoo_openupgrade_wizard import templates
|
||||
|
||||
|
||||
def get_script_folder(ctx, migration_step: dict) -> Path:
|
||||
return ctx.obj["script_folder_path"] / migration_step["complete_name"]
|
||||
|
||||
|
||||
def ensure_folder_exists(
|
||||
folder_path: Path, mode: str = "755", git_ignore_content: bool = False
|
||||
):
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ def test_cli_execute_script():
|
|||
[
|
||||
"--log-level=DEBUG",
|
||||
"--env-folder=%s" % output_folder_path,
|
||||
"execute-script",
|
||||
"execute-script-python",
|
||||
"--step=1",
|
||||
"--database=%s" % db_name,
|
||||
"--script-file-path=%s" % extra_script_path,
|
||||
|
|
@ -9,6 +9,9 @@ from . import cli_runner_invoke
|
|||
|
||||
|
||||
def test_cli_upgrade():
|
||||
# TODO: FIXME
|
||||
# This test works locally, but doesn't work on gitlabci
|
||||
|
||||
output_folder_path = Path("./tests/output_B").absolute()
|
||||
|
||||
db_name = "database_test_cli_upgrade"
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user