From 6df0ec7d8eb5c201c7669e890942eb3d02e3a290 Mon Sep 17 00:00:00 2001 From: Eric Antones Date: Mon, 20 Jul 2026 18:12:33 +0200 Subject: [PATCH] [17.0][OU-FIX] sms: fill sms_sms.uuid per row before the ORM creates the column The uuid field (new in 17.0) has a callable default and a unique constraint, but no migration script fills it for pre-existing rows. The ORM creates the column during the upgrade and evaluates the default once, so every existing row gets the same value and the uuid_unique constraint fails to install. Pre-create the column and backfill a deterministic per-row value (md5 over the id, same 32-hex shape as uuid4().hex). Also breaks any duplicate group left by a previous upgrade run without this script. --- .../scripts/sms/17.0.3.0/pre-migration.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 openupgrade_scripts/scripts/sms/17.0.3.0/pre-migration.py diff --git a/openupgrade_scripts/scripts/sms/17.0.3.0/pre-migration.py b/openupgrade_scripts/scripts/sms/17.0.3.0/pre-migration.py new file mode 100644 index 000000000000..aa7937dc46fa --- /dev/null +++ b/openupgrade_scripts/scripts/sms/17.0.3.0/pre-migration.py @@ -0,0 +1,31 @@ +# Copyright 2026 NuoBiT Solutions - Eric Antones +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + """Pre-create sms_sms.uuid filled with one value per row. + + The uuid field (new in 17.0) is declared with a callable default and + a unique constraint. Without this script the ORM creates the column + during the upgrade and evaluates the default only once, so every + pre-existing row receives the same value and the uuid_unique + constraint fails to install. + """ + if not openupgrade.column_exists(env.cr, "sms_sms", "uuid"): + openupgrade.logged_query(env.cr, "ALTER TABLE sms_sms ADD COLUMN uuid varchar") + # Fill missing values and break any duplicate group left by a + # previous upgrade run without this script (deterministic per id, + # same 32-hex shape as uuid4().hex, idempotent). + openupgrade.logged_query( + env.cr, + """ + UPDATE sms_sms + SET uuid = md5('sms_sms-uuid-' || id::text) + WHERE uuid IS NULL + OR uuid IN ( + SELECT uuid FROM sms_sms GROUP BY uuid HAVING count(*) > 1 + ) + """, + )