SQL Constraint Deleted

From version 14.0 to version 15.0, in the module bus, the constraint named bus_user_presence_unique on table bus_presence has been deleted.

Analysis

...
---Fields in module 'bus'---
...
---XML records in module 'bus'---
DEL ir.model.constraint: bus.constraint_bus_presence_bus_user_presence_unique

See Full V15 Analysis File.

Source Code Differences

Version 14.0

class BusPresence(models.Model):
    _name = "bus.presence"

    _sql_constraints = [
        (
            "bus_user_presence_unique",
            "unique(user_id)",
            "A user can only have one IM status.",
        ),
    ]

See Full V14 Code Source.

Version 15.0

class BusPresence(models.Model):
    _name = "bus.presence"

See Full V15 Code Source.

Contribution to OpenUpgrade

Update upgrade_analysis_work.txt file

  • Mention the operation performed, starting with # DONE:

---Fields in module 'bus'---
---XML records in module 'bus'---
DEL ir.model.constraint: bus.constraint_bus_presence_bus_user_presence_unique
# DONE: pre-migration: deleted safely

See Full V15 Work Analysis File.

Write migration Script

in the pre-migration.py script add:

from openupgradelib import openupgrade

@openupgrade.migrate()
def migrate(env, version):
    # Disappeared constraint
    openupgrade.delete_sql_constraint_safely(
        env,
        "bus",                          # Module name
        "bus_presence",                 # Table name
        "bus_user_presence_unique",     # SQL constraint name
    )

See Full pre migration Script.