[ADD] various: deduplicate soon-to-be-unique fields before migration
Some target versions add a ``UNIQUE`` constraint on a field that allowed duplicates in the source version (e.g. ``utm.source.name`` in 16.0). The unique index creation then aborts the whole registry load with a ``psycopg2.errors.UniqueViolation``. Declare such constraints per version in ``known_changes.yaml`` under the ``new_unique_constraints`` key (only ``model`` and ``fields`` needed). During ``prepare_db.sh``, ``dedup_unique_constraints.py`` aggregates the declarations of every traversed version and, on the source database, renames duplicates by suffixing `` [<id>]`` while preserving foreign keys. The actual PostgreSQL column type is used (not the ORM ``translate`` attribute) so both ``varchar`` and already-converted ``jsonb`` columns are handled: ``jsonb`` duplicates are compared and renamed on every language key (indexed ``en_US`` value). Renamed records are reported in a timestamped JSON file and summarized at the end of ``migration.log``.
This commit is contained in:
@@ -21,3 +21,12 @@ renamed:
|
||||
new: server_action_mass_edit
|
||||
- old: crm_project
|
||||
new: crm_lead_to_task
|
||||
|
||||
# Unique constraints newly introduced in 16.0
|
||||
new_unique_constraints:
|
||||
- model: utm.source
|
||||
fields: [name]
|
||||
- model: utm.medium
|
||||
fields: [name]
|
||||
- model: utm.campaign
|
||||
fields: [name]
|
||||
|
||||
Reference in New Issue
Block a user