[migration] add_workflow now ensure the entity type is actually workflowable, and a new make_workflowable migration function is available to make an entity type workflowable (closes #1382720) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 11 Jan 2011 15:33:38 +0100
branchstable
changeset 6805 d0d7345581d4
parent 6804 4262d0d6abcb
child 6806 8291f5e0c9f6
[migration] add_workflow now ensure the entity type is actually workflowable, and a new make_workflowable migration function is available to make an entity type workflowable (closes #1382720)
server/migractions.py
--- a/server/migractions.py	Tue Jan 11 15:23:29 2011 +0100
+++ b/server/migractions.py	Tue Jan 11 15:33:38 2011 +0100
@@ -1218,6 +1218,12 @@
 
     # Workflows handling ######################################################
 
+    def cmd_make_workflowable(self, etype):
+        """add workflow relations to an entity type to make it workflowable"""
+        self.cmd_add_relation_definition(etype, 'in_state', 'State')
+        self.cmd_add_relation_definition(etype, 'custom_workflow', 'Workflow')
+        self.cmd_add_relation_definition('TrInfo', 'wf_info_for', etype)
+
     def cmd_add_workflow(self, name, wfof, default=True, commit=False,
                          **kwargs):
         """
@@ -1239,7 +1245,13 @@
                                     **kwargs)
         if not isinstance(wfof, (list, tuple)):
             wfof = (wfof,)
+        def _missing_wf_rel(etype):
+            return 'missing workflow relations, see make_workflowable(%s)' % etype
         for etype in wfof:
+            eschema = self.repo.schema[etype]
+            assert 'in_state' in eschema.subjrels, _missing_wf_rel(etype)
+            assert 'custom_workflow' in eschema.subjrels, _missing_wf_rel(etype)
+            assert 'wf_info_for' in eschema.objrels, _missing_wf_rel(etype)
             rset = self.rqlexec(
                 'SET X workflow_of ET WHERE X eid %(x)s, ET name %(et)s',
                 {'x': wf.eid, 'et': etype}, ask_confirm=False)