From 0c928dd4e762c6aaa0051cb6aed169de118a1f9d 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 Adds openupgrade_scripts/scripts/iap/19.0.1.1/post-migration.py to map the openupgrade_legacy_18_0_service_name column onto iap_account.service_id for rows left half-migrated by an earlier major-version upgrade. DBs in this shape have rows where service_id IS NULL despite 19.0's required=True declaration, producing a "Missing not-null constraint on iap.account.service_id" warning at schema sync. The backfill resolves those rows by matching the preserved legacy service_name against iap_service.technical_name. Marks the iap row in docsource/modules180-190.rst as Done. --- docsource/modules180-190.rst | 2 +- .../scripts/iap/19.0.1.1/post-migration.py | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 openupgrade_scripts/scripts/iap/19.0.1.1/post-migration.py diff --git a/docsource/modules180-190.rst b/docsource/modules180-190.rst index fd4b86e2175e..18929bdd758b 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 | |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..99d6a07679dc --- /dev/null +++ b/openupgrade_scripts/scripts/iap/19.0.1.1/post-migration.py @@ -0,0 +1,35 @@ +# 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 column was named when an earlier major-version migration + # preserved iap_account.service_name; depending on the DB's history the + # prefix can be openupgrade_legacy__0_*. Look it up dynamically. + 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 + """, + )