From afeaa3d00f33917ab5416720c6b817b8e9851850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Mon, 12 Jan 2026 17:08:43 +0100 Subject: [PATCH] [IMP] fix the issue of account_analytic_plan migration in v17 Should be great to understand the origin of the problem one day... --- 17.0/post_upgrade.sh | 26 ++++++++++++++++++++++++++ 17.0/pre_upgrade.sh | 42 +++++++++++++++++++++++++++++++++++++++++- 18.0/pre_upgrade.sh | 5 ++++- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/17.0/post_upgrade.sh b/17.0/post_upgrade.sh index aba2fce..2caebed 100755 --- a/17.0/post_upgrade.sh +++ b/17.0/post_upgrade.sh @@ -2,4 +2,30 @@ echo "Post migration to 17.0..." +# Execute SQL post-migration commands +POST_MIGRATE_SQL=$(cat <<'EOF' +DO $$ +DECLARE + plan_id INTEGER; +BEGIN + -- Check if the 'Projects' analytic plan exists + SELECT id INTO plan_id FROM account_analytic_plan WHERE complete_name = 'migration_PROJECTS' LIMIT 1; + + -- If it does exist, delete it + IF plan_id IS NOT NULL THEN + DELETE FROM account_analytic_plan WHERE complete_name = 'migration_PROJECTS'; + SELECT id INTO plan_id FROM account_analytic_plan WHERE complete_name = 'Projects' LIMIT 1; + -- Delete existing system parameter (if any) + DELETE FROM ir_config_parameter WHERE key = 'analytic.project_plan'; + -- Insert the system parameter with the correct plan ID + INSERT INTO ir_config_parameter (key, value, create_date, write_date) + VALUES ('analytic.project_plan', plan_id::text, now(), now()); + END IF; +END $$; +EOF +) +echo "SQL command = $POST_MIGRATE_SQL" +query_postgres_container "$POST_MIGRATE_SQL" ou17 || exit 1 + + #compose --debug run ou17 -u base --stop-after-init --no-http diff --git a/17.0/pre_upgrade.sh b/17.0/pre_upgrade.sh index 618c74f..7b8a5fc 100755 --- a/17.0/pre_upgrade.sh +++ b/17.0/pre_upgrade.sh @@ -6,10 +6,50 @@ echo "Prepare migration to 17.0..." copy_database ou16 ou17 ou17 || exit 1 # Execute SQL pre-migration commands -PRE_MIGRATE_SQL="" +PRE_MIGRATE_SQL=$(cat <<'EOF' +DO $$ +DECLARE + plan_id INTEGER; +BEGIN + -- Check if the 'Projects' analytic plan exists + SELECT id INTO plan_id FROM account_analytic_plan WHERE name = 'Projects' LIMIT 1; + + -- If it doesn't exist, create it + IF plan_id IS NULL THEN + INSERT INTO account_analytic_plan (name, complete_name, default_applicability, create_date, write_date) + VALUES ('Projects', 'migration_PROJECTS', 'optional', now(), now()) + RETURNING id INTO plan_id; + END IF; + + -- Delete existing system parameter (if any) + DELETE FROM ir_config_parameter WHERE key = 'analytic.project_plan'; + + -- Insert the system parameter with the correct plan ID + INSERT INTO ir_config_parameter (key, value, create_date, write_date) + VALUES ('analytic.project_plan', plan_id::text, now(), now()); +END $$; +EOF +) echo "SQL command = $PRE_MIGRATE_SQL" query_postgres_container "$PRE_MIGRATE_SQL" ou17 || exit 1 +PRE_MIGRATE_SQL_2=$(cat <<'EOF' +DELETE FROM ir_model_fields WHERE name = 'kanban_state_label'; +EOF +) +echo "SQL command = $PRE_MIGRATE_SQL_2" +query_postgres_container "$PRE_MIGRATE_SQL_2" ou17 || exit 1 + +PRE_MIGRATE_SQL_3=$(cat <<'EOF' +DELETE FROM ir_model_fields WHERE name = 'phone' AND model='hr.employee'; +DELETE FROM ir_model_fields WHERE name = 'hr_responsible_id' AND model='hr.job'; +DELETE FROM ir_model_fields WHERE name = 'address_home_id' AND model='hr.employee'; +DELETE FROM ir_model_fields WHERE name = 'manager_id' AND model='project.task'; +EOF +) +echo "SQL command = $PRE_MIGRATE_SQL_3" +query_postgres_container "$PRE_MIGRATE_SQL_3" ou17 || exit 1 + # Copy filestores copy_filestore ou16 ou16 ou17 ou17 || exit 1 diff --git a/18.0/pre_upgrade.sh b/18.0/pre_upgrade.sh index a05a790..29953fd 100755 --- a/18.0/pre_upgrade.sh +++ b/18.0/pre_upgrade.sh @@ -6,7 +6,10 @@ echo "Prepare migration to 18.0..." copy_database ou17 ou18 ou18 || exit 1 # Execute SQL pre-migration commands -PRE_MIGRATE_SQL="" +PRE_MIGRATE_SQL=$(cat <<'EOF' +UPDATE account_analytic_plan SET default_applicability=NULL WHERE default_applicability='optional'; +EOF +) echo "SQL command = $PRE_MIGRATE_SQL" query_postgres_container "$PRE_MIGRATE_SQL" ou18 || exit 1