From 4fc70569324b04f19dd9042ac579e7de68ebe211 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Sun, 2 Feb 2025 18:33:41 +0100 Subject: [PATCH 1/2] [IMP] oow upgrade. Add skip_update as an option in config.yml. (migration_step option). If enabled, in this step, the update all will be skipped, and only pre-migration (SQL) and post-migration (python script) will be executed. This is interesting: - for the first step, if your production is up-to-date, to save time. - for the last step, in recent version (since V14), where openupgrade doesn't contain odoo code. In that case, you should be sure that all your migration is OK, because in openupgrade context, some errors are just ignored. Use this option with caution. --- README.md | 6 ++- .../+add-option-no-update-all.feature | 4 ++ odoo_openupgrade_wizard/cli/cli_upgrade.py | 37 ++++++++++++------- .../templates/config.yml.j2 | 3 ++ tests/data/output_expected/config.yml | 2 + 5 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 newsfragments/+add-option-no-update-all.feature diff --git a/README.md b/README.md index 8cab272..a7f4aad 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,11 @@ modules.csv the classical keys (``db_host``, ``db_port``, etc...) are automatically autogenerated. -At this step, you should change the autogenerated files. +At this step, you should change the autogenerated files. For exemple: +- you can set ``skip_update=True`` to prevents to run an update=all, in the 'regular' steps + (first and last steps). In that case, only SQL queries and python scripts + will be executed during this step. + You can use default files, if you have a very simple odoo instance without custom code, extra repositories, or dependencies... diff --git a/newsfragments/+add-option-no-update-all.feature b/newsfragments/+add-option-no-update-all.feature new file mode 100644 index 0000000..f3c0690 --- /dev/null +++ b/newsfragments/+add-option-no-update-all.feature @@ -0,0 +1,4 @@ +Add an option ``skip_update`` in the configuration file at migration_step level. +If enabled, the update=all step will be skipped during this step. +That can be interesting to save time, during the first and the last steps of the migration +process (when ``execution_context='regular'). diff --git a/odoo_openupgrade_wizard/cli/cli_upgrade.py b/odoo_openupgrade_wizard/cli/cli_upgrade.py index a29bf41..b49742c 100644 --- a/odoo_openupgrade_wizard/cli/cli_upgrade.py +++ b/odoo_openupgrade_wizard/cli/cli_upgrade.py @@ -30,18 +30,29 @@ def upgrade(ctx, first_step, last_step, database, with_demo): ) for migration_step in migration_steps: execute_sql_files_pre_migration(ctx, database, migration_step) - try: - run_odoo( - ctx, - migration_step, - database=database, - detached_container=False, - update="all", - stop_after_init=True, - demo=with_demo, + if not migration_step.get("skip_update", False): + try: + run_odoo( + ctx, + migration_step, + database=database, + detached_container=False, + update="all", + stop_after_init=True, + demo=with_demo, + ) + except (KeyboardInterrupt, SystemExit): + logger.info("Received Keyboard Interrupt or System Exiting...") + finally: + kill_odoo(ctx, database, migration_step) + elif migration_step.get("execution_context") == "openupgrade": + logger.warning( + "Incorrect setting skip_update = True" + " and execution_context = 'openupgrade'..." ) - except (KeyboardInterrupt, SystemExit): - logger.info("Received Keyboard Interrupt or System Exiting...") - finally: - kill_odoo(ctx, database, migration_step) + else: + logger.info( + f"Skip update all for version {migration_step.get('version')}." + ) + execute_click_odoo_python_files(ctx, database, migration_step) diff --git a/odoo_openupgrade_wizard/templates/config.yml.j2 b/odoo_openupgrade_wizard/templates/config.yml.j2 index 6b6ca36..d9cc8d6 100644 --- a/odoo_openupgrade_wizard/templates/config.yml.j2 +++ b/odoo_openupgrade_wizard/templates/config.yml.j2 @@ -31,6 +31,9 @@ migration_steps: version: {{ step['version'] }} execution_context: {{ step['execution_context'] }} complete_name: {{ step['complete_name'] }} + {%- if step['execution_context'] == 'regular'%} + skip_update: False + {%- endif %} {% endfor %} workload_settings: diff --git a/tests/data/output_expected/config.yml b/tests/data/output_expected/config.yml index 03627e8..c64bc57 100644 --- a/tests/data/output_expected/config.yml +++ b/tests/data/output_expected/config.yml @@ -28,6 +28,7 @@ migration_steps: version: 14.0 execution_context: regular complete_name: step_01__regular__14.0 + skip_update: False - name: 2 version: 15.0 @@ -38,6 +39,7 @@ migration_steps: version: 15.0 execution_context: regular complete_name: step_03__regular__15.0 + skip_update: False workload_settings: From bfde1ddc1fcc2bdb6e196e9c1141feeb2d79983e Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Tue, 11 Feb 2025 10:45:25 +0100 Subject: [PATCH 2/2] fixup! [IMP] oow upgrade. Add skip_update as an option in config.yml. (migration_step option). If enabled, in this step, the update all will be skipped, and only pre-migration (SQL) and post-migration (python script) will be executed. This is interesting: - for the first step, if your production is up-to-date, to save time. - for the last step, in recent version (since V14), where openupgrade doesn't contain odoo code. In that case, you should be sure that all your migration is OK, because in openupgrade context, some errors are just ignored. Use this option with caution. --- README.md | 2 +- newsfragments/+add-option-no-update-all.feature | 4 ++-- odoo_openupgrade_wizard/cli/cli_upgrade.py | 11 ++++++----- odoo_openupgrade_wizard/templates/config.yml.j2 | 2 +- tests/data/output_expected/config.yml | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a7f4aad..63d2df4 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,7 @@ modules.csv autogenerated. At this step, you should change the autogenerated files. For exemple: -- you can set ``skip_update=True`` to prevents to run an update=all, in the 'regular' steps +- you can set ``update=False`` to prevents to run an update=all, in the 'regular' steps (first and last steps). In that case, only SQL queries and python scripts will be executed during this step. diff --git a/newsfragments/+add-option-no-update-all.feature b/newsfragments/+add-option-no-update-all.feature index f3c0690..3e1ea61 100644 --- a/newsfragments/+add-option-no-update-all.feature +++ b/newsfragments/+add-option-no-update-all.feature @@ -1,4 +1,4 @@ -Add an option ``skip_update`` in the configuration file at migration_step level. -If enabled, the update=all step will be skipped during this step. +Add an option ``update`` in the configuration file at migration_step level. +If disabled, the update=all step will be skipped during this step. That can be interesting to save time, during the first and the last steps of the migration process (when ``execution_context='regular'). diff --git a/odoo_openupgrade_wizard/cli/cli_upgrade.py b/odoo_openupgrade_wizard/cli/cli_upgrade.py index b49742c..a7e06c0 100644 --- a/odoo_openupgrade_wizard/cli/cli_upgrade.py +++ b/odoo_openupgrade_wizard/cli/cli_upgrade.py @@ -30,7 +30,7 @@ def upgrade(ctx, first_step, last_step, database, with_demo): ) for migration_step in migration_steps: execute_sql_files_pre_migration(ctx, database, migration_step) - if not migration_step.get("skip_update", False): + if migration_step.get("update", True): try: run_odoo( ctx, @@ -46,13 +46,14 @@ def upgrade(ctx, first_step, last_step, database, with_demo): finally: kill_odoo(ctx, database, migration_step) elif migration_step.get("execution_context") == "openupgrade": - logger.warning( - "Incorrect setting skip_update = True" - " and execution_context = 'openupgrade'..." + raise ValueError( + "Incorrect setting 'update: True'" + " and 'execution_context: openupgrade'" ) else: logger.info( - f"Skip update all for version {migration_step.get('version')}." + "Skip update=all for" + f" step {migration_step.get('complete_name')}" ) execute_click_odoo_python_files(ctx, database, migration_step) diff --git a/odoo_openupgrade_wizard/templates/config.yml.j2 b/odoo_openupgrade_wizard/templates/config.yml.j2 index d9cc8d6..5b0caab 100644 --- a/odoo_openupgrade_wizard/templates/config.yml.j2 +++ b/odoo_openupgrade_wizard/templates/config.yml.j2 @@ -32,7 +32,7 @@ migration_steps: execution_context: {{ step['execution_context'] }} complete_name: {{ step['complete_name'] }} {%- if step['execution_context'] == 'regular'%} - skip_update: False + update: True {%- endif %} {% endfor %} diff --git a/tests/data/output_expected/config.yml b/tests/data/output_expected/config.yml index c64bc57..af81604 100644 --- a/tests/data/output_expected/config.yml +++ b/tests/data/output_expected/config.yml @@ -28,7 +28,7 @@ migration_steps: version: 14.0 execution_context: regular complete_name: step_01__regular__14.0 - skip_update: False + update: True - name: 2 version: 15.0 @@ -39,7 +39,7 @@ migration_steps: version: 15.0 execution_context: regular complete_name: step_03__regular__15.0 - skip_update: False + update: True workload_settings: