From 5c4a106ec09b8da748c869f61b6a331d4df799d4 Mon Sep 17 00:00:00 2001 From: Don Kendall Date: Tue, 26 May 2026 19:39:39 -0400 Subject: [PATCH] [OU-ADD] iap: backfill service_id from legacy service_name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upgrade-scarred DBs keep the preserved legacy column with service_id NULL despite 19.0's required=True — warns at every schema sync until relinked. --- docsource/modules180-190.rst | 2 +- .../scripts/iap/19.0.1.1/post-migration.py | 33 +++++++++++++++++++ .../scripts/iap/tests/data_iap_migration.py | 20 +++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 openupgrade_scripts/scripts/iap/19.0.1.1/post-migration.py create mode 100644 openupgrade_scripts/scripts/iap/tests/data_iap_migration.py diff --git a/docsource/modules180-190.rst b/docsource/modules180-190.rst index 12da4e5fbaea..bd8b57ca4834 100644 --- a/docsource/modules180-190.rst +++ b/docsource/modules180-190.rst @@ -232,7 +232,7 @@ Module coverage 18.0 -> 19.0 +---------------------------------------------------+----------------------+-------------------------------------------------+ | http_routing |Nothing to do | | +---------------------------------------------------+----------------------+-------------------------------------------------+ -| iap |Nothing to do |No DB layout changes. | +| iap |Done |Backfill service_id from legacy service_name. | +---------------------------------------------------+----------------------+-------------------------------------------------+ | iap_crm | |No DB layout changes. | +---------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/iap/19.0.1.1/post-migration.py b/openupgrade_scripts/scripts/iap/19.0.1.1/post-migration.py new file mode 100644 index 000000000000..93a0efc839aa --- /dev/null +++ b/openupgrade_scripts/scripts/iap/19.0.1.1/post-migration.py @@ -0,0 +1,33 @@ +# Copyright 2026 Ledo +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + # the legacy prefix (openupgrade_legacy__0_*) depends on the DB's history + env.cr.execute( + """ + SELECT column_name + FROM information_schema.columns + WHERE table_name = 'iap_account' + AND column_name LIKE 'openupgrade_legacy_%_service_name' + ORDER BY column_name + LIMIT 1 + """ + ) + row = env.cr.fetchone() + if not row: + return + legacy_col = row[0] + openupgrade.logged_query( + env.cr, + f""" + UPDATE iap_account a + SET service_id = s.id + FROM iap_service s + WHERE a.service_id IS NULL + AND a.{legacy_col} = s.technical_name + """, + ) diff --git a/openupgrade_scripts/scripts/iap/tests/data_iap_migration.py b/openupgrade_scripts/scripts/iap/tests/data_iap_migration.py new file mode 100644 index 000000000000..5f1d54533273 --- /dev/null +++ b/openupgrade_scripts/scripts/iap/tests/data_iap_migration.py @@ -0,0 +1,20 @@ +env = locals().get("env") + +# Recreate the upgrade-scarred shape (preserved legacy column + unlinked row) +# so the post-migration backfill has rows to move on the fresh CI seed. +env.cr.execute( + "ALTER TABLE iap_account " + "ADD COLUMN IF NOT EXISTS openupgrade_legacy_18_0_service_name varchar" +) +env.cr.execute("ALTER TABLE iap_account ALTER COLUMN service_id DROP NOT NULL") +env.cr.execute( + """ + INSERT INTO iap_account (openupgrade_legacy_18_0_service_name) + SELECT s.technical_name FROM iap_service s + WHERE NOT EXISTS ( + SELECT 1 FROM iap_account + WHERE openupgrade_legacy_18_0_service_name IS NOT NULL) + LIMIT 1 + """ +) +env.cr.commit()