Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions openupgrade_scripts/scripts/sms/17.0.3.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2026 NuoBiT Solutions - Eric Antones <eantones@nuobit.com>
# 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
)
""",
)
Loading