diff --git a/arkindex/process/migrations/0005_migrate_workflows.py b/arkindex/process/migrations/0005_migrate_workflows.py index 85d888a1ab59d8494cd054ee44b1a5d869f4d696..bd02626a26c49d0b068e5e8e18bc3e1205003833 100644 --- a/arkindex/process/migrations/0005_migrate_workflows.py +++ b/arkindex/process/migrations/0005_migrate_workflows.py @@ -14,6 +14,19 @@ class Migration(migrations.Migration): operations = [ migrations.RunSQL( [ + # In some rare cases, the workflow creation date is set a few milliseconds + # before the process creation date, breaking the process_started_after_created constraint + """ + update ponos_workflow w + set created = data.created + from ( + select w.id, p.created + from process_process p + inner join ponos_workflow w on (w.id=p.workflow_id) + where w.created < p.created + ) data + where data.id=w.id; + """, # This query cannot be done with QuerySet.update, because Django does not allow joining during an update. # This is why we use RunSQL here and not RunPython. """