[saem-devel] [PATCH 3 of 3] [migration] Add migration script to set ark on existing organizations

Sylvain Thenault sylvain.thenault at logilab.fr
Wed Feb 8 10:55:48 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1486455063 -3600
#      Tue Feb 07 09:11:03 2017 +0100
# Node ID b6b6cf96bef0e1ee9dd0c58f2bf7ceaaf5cc2944
# Parent  4e5e28519eb9b90ce2f2ec76e6fed21ee53aa4f8
[migration] Add migration script to set ark on existing organizations

The 0.14.0 migration script added the attribute but didn't set it on
pre-existing organization.

diff --git a/cubicweb_saem_ref/migration/0.14.3_Any.py b/cubicweb_saem_ref/migration/0.14.3_Any.py
new file mode 100644
--- /dev/null
+++ b/cubicweb_saem_ref/migration/0.14.3_Any.py
@@ -0,0 +1,18 @@
+from cubicweb_saem_ref.hooks import set_ark_and_cwuri
+
+
+def fix_organization_ark(cnx):
+    with cnx.security_enabled(write=False):
+        rset = cnx.execute('Any O WHERE O ark NULL, O is Organization')
+        for i, org in enumerate(rset.entities()):
+            if org.ark_naa:
+                naa_what = org.ark_naa[0].what
+            else:
+                naa_what = u'XXX'
+            attrs = {}
+            set_ark_and_cwuri(cnx, org.eid, 'Organization', attrs, naa_what=naa_what)
+            org.cw_set(**attrs)
+        cnx.commit()
+
+
+fix_organization_ark(cnx)


More information about the saem-devel mailing list