[migration] a few simplifications and fixes
- use rename_relation_type instead of deprecated rename_relation
- look at Plan's default workflow, not any workflow
- we don't need to log in as narval, managers should be able to fire
transitions
- avoid a few useless sync_schema_props_perms calls
- drop TestExecution.arguments
--- a/migration/3.0.0_Any.py Fri Apr 25 15:21:09 2014 +0200
+++ b/migration/3.0.0_Any.py Fri Apr 25 15:55:10 2014 +0200
@@ -4,17 +4,16 @@
schema.rebuild_infered_relations()
# TestExecution now have a workflow
-rql('SET WF workflow_of TE, TE default_workflow WF WHERE WF workflow_of P, '
+rql('SET WF workflow_of TE, TE default_workflow WF WHERE P default_workflow WF, '
'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')
+rename_relation_type('log_file','execution_archive')
commit()
-# for each TestExecution, Plan ...
-
+# for each TestExecution...
te_eids = rql('DISTINCT Any X WHERE '
'X is TestExecution, '
'NOT TI wf_info_for X, '
@@ -27,34 +26,28 @@
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()
-
+# fire all necessary transitions
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()
+ te = 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))
# 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))
+ rql('SET TI creation_date %(date)s WHERE TI eid %(eid)s',
+ {'date': date, 'eid': eid})
commit()
add_relation_type('log_file')
@@ -63,15 +56,12 @@
drop_attribute('TestExecution', 'starttime')
drop_attribute('TestExecution', 'endtime')
drop_attribute('TestExecution', 'execution_status')
+drop_attribute('TestExecution', 'arguments')
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 ?'):
+if confirm('Upgrade all log_files to file objects?'):
for xeid, fcontent in rset:
if fcontent is not None:
log_file = create_entity('File', data_name=u"log_file.txt",