[migration] fix migration to mirror narval (closes #3687137)
- log_files contained the archive of the run, they have been renamed to
execution_archive
- make sure the schema inherited entities are updated
- create workflow data for all testexecutions
--- a/migration/3.0.0_Any.py Mon Mar 24 10:17:30 2014 +0100
+++ b/migration/3.0.0_Any.py Thu Mar 27 16:46:29 2014 +0100
@@ -1,21 +1,75 @@
# -*- coding: utf-8 -*-
from cubicweb import Binary
+from cubicweb.server.session import Session
+schema.rebuild_infered_relations()
# TestExecution now have a workflow
rql('SET WF workflow_of TE, TE default_workflow WF WHERE WF workflow_of P, '
'P name "Plan", TE name "TestExecution"')
commit()
+# transform log into log_files
+rset = rql('Any X, F WHERE X is IN (TestExecution, CheckResult), X log F')
rename_relation('log_file','execution_archive')
commit()
-# transform log into log_files
-rset = rql('Any X, F WHERE X is IN (TestExecution, CheckResult), X log F')
+# for each TestExecution, Plan ...
+
+te_eids = rql('DISTINCT Any X WHERE '
+ 'X is TestExecution, '
+ 'NOT TI wf_info_for X, '
+ 'NOT X in_state S'
+ )
+
+# set it in correct initial state
+for (eid,) in te_eids:
+ session.entity_from_eid(eid).cw_adapt_to('IWorkflowable').set_initial_state('ready')
+
+commit()
+
+#fire all necessary transitions
+narval_user = rql('Any U WHERE U in_group G, G name "narval"').get_entity(0,0)
+narval_session = Session(narval_user, repo)
+narval_session.set_cnxset()
+
+to_update=[]
+for (eid,) in te_eids:
+ te = narval_session.entity_from_eid(eid)
+ if te.starttime:
+ tri = te.cw_adapt_to('IWorkflowable').fire_transition('start')
+ to_update.append((tri.eid, te.starttime))
+ if te.endtime:
+ if te.status == 'success':
+ tri = te.cw_adapt_to('IWorkflowable').fire_transition('end')
+ to_update.append((tri.eid, te.endtime))
+ elif te.status == 'killed':
+ tri = te.cw_adapt_to('IWorkflowable').fire_transition('kill')
+ to_update.append((tri.eid, te.endtime))
+ else:
+ tri = te.cw_adapt_to('IWorkflowable').fire_transition('fail')
+ to_update.append((tri.eid, te.endtime))
+
+narval_session.commit()
+narval_session.close()
+
+# set correct timestamps
+for eid, date in to_update:
+ rql('SET TI creation_date %(date)s WHERE TI eid %(eid)s ', dict(date=date, eid=eid))
+commit()
+
add_relation_type('log_file')
+drop_attribute('CheckResult', 'log')
drop_attribute('TestExecution', 'log')
-drop_attribute('CheckResult', 'log')
+drop_attribute('TestExecution', 'starttime')
+drop_attribute('TestExecution', 'endtime')
+drop_attribute('TestExecution', 'execution_status')
-sync_schema_props_perms()
+sync_schema_props_perms('CheckResult')
+sync_schema_props_perms('TestExecution')
+sync_schema_props_perms('use_environment')
+sync_schema_props_perms('execution_log')
+sync_schema_props_perms('has_apycot_environment')
+
if confirm('Upgrade all log_files to file objects ?'):
for xeid, fcontent in rset:
@@ -50,3 +104,5 @@
rql('SET X script %(script)s WHERE X execution_of Y, Y name %(name)s',
{'script': warning_msg + r_script_names[r_name],
'name': r_name})
+
+