server/migractions.py
branchstable
changeset 6805 d0d7345581d4
parent 6686 070e3b23160d
child 6815 a84190d4e78c
--- 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)