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

Sylvain Thenault sylvain.thenault at logilab.fr
Tue Feb 21 15:03:54 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 c98304446b56ff4cb2d861612e37a529f5419e37
# Parent  f0eb1da37bd34492aecc64f4699c221f0c8f8cf8
[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,20 @@
+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 org in rset.entities():
+            if org.ark_naa:
+                naa_what = org.ark_naa[0].what
+            else:
+                # set dumb naa what that will have to be fixed later by hand,
+                # but at least it will appear in the UI
+                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