[PATCH saem v2] [migration] Fix migration to deduplicate agents
sylvain.thenault at logilab.fr
Fri Apr 14 10:47:49 CEST 2017
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1492079286 -7200
# Thu Apr 13 12:28:06 2017 +0200
# Node ID 69b57fc07d4ae71c366348ff4ddb793745ea0b74
# Parent 3019df2c985307fef4158c85e50cf682c9a26191
# Available At http://hg.logilab.org/review/cubes/saem_ref
# hg pull http://hg.logilab.org/review/cubes/saem_ref -r 69b57fc07d4a
[migration] Fix migration to deduplicate agents
This migration script introduce a unique together constraint on Agent(authority,
name), but it appears that e.g. there are several agent with the same name
within the same authority in our demo instance's database (historically due to
the way EAC import was working, but this shouldn't happen anymore).
So prior to synchronize Agent type, we should handle this else attempt to add
unique constraint on (authority, name) will fail.
Deduplicate is done naivly by keeping one arbitrarily and remove all others,
because test instances should not care that much and we don't want to spend more
time on this.
diff --git a/cubicweb_saem_ref/migration/0.15.1_Any.py b/cubicweb_saem_ref/migration/0.15.1_Any.py
@@ -1,5 +1,12 @@
+# quick and dirty deduplicate of agent with duplicated name within an authority
+for agent in rql('DISTINCT Any X WHERE X is Agent, X name XN, X authority A, '
+ 'Y is Agent, Y name XN, Y authority A, '
+ 'Y eid YE, X eid >YE').entities():
for ertype in ('generated', 'used', 'associated_with', 'place_address', 'new_version_of',
'OrganizationUnit', 'Agent', 'ArkNameAssigningAuthority'):
More information about the saem-devel