[PATCH saem] [migration] Fix migration to deduplicate agents

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Apr 13 12:28:19 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 f086cb23dfbb4b70b56ad4077440e15fcba2ce92
# Parent  69d50b0e6564de38fc4418d42bfdaf0e6395ef48
[migration] Fix migration to deduplicate agents

else attemp to add unique constraint on (authority, name) will fail.

Deduplicate is done naivly because test instances should not care that much.

diff --git a/cubicweb_saem_ref/migration/0.15.1_Any.py b/cubicweb_saem_ref/migration/0.15.1_Any.py
--- 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():
+    agent.cw_delete()
 for ertype in ('generated', 'used', 'associated_with', 'place_address', 'new_version_of',
                'agent_kind', 'authority_record',
                'OrganizationUnit', 'Agent', 'ArkNameAssigningAuthority'):

More information about the saem-devel mailing list