Skip to content

Fix workflow migrations: remove redundant duplicates that break fresh-DB migrate - #67

Merged
IzBrain67 merged 1 commit into
mainfrom
fix/workflow-migration-redundancy
Jun 23, 2026
Merged

Fix workflow migrations: remove redundant duplicates that break fresh-DB migrate#67
IzBrain67 merged 1 commit into
mainfrom
fix/workflow-migration-redundancy

Conversation

@IzBrain67

Copy link
Copy Markdown
Collaborator

Fixes #65.

Problem

On a clean setup the backend crash-loops on startup — manage.py migrate fails with:

django.db.utils.ProgrammingError: column "workflow_context" of relation "flow_projects" already exists

This blocks every fresh environment (new clone, CI, docker compose down -v reset, a new contributor's first run). Databases that were already migrated are unaffected, which is why it went unnoticed on main.

Root cause

The migration set is internally inconsistent. 0001_initial was regenerated into a full snapshot in commit 8d9fdb23 ("Track Django migrations and stop auto-generation") — it already creates FlowProject.workflow_context and the WorkflowRun model. After that, main was a consistent 3-migration chain.

PR #55 (98af506a) then added a parallel branch of locally auto-generated migrations on top of that snapshot:

Migration Operation Already done by
0002_flowproject_workflow_context AddField workflow_context 0001_initial
0003_workflowrun CreateModel WorkflowRun 0001_initial
0004_flowproject_hpc_target_flowproject_reference_and_more AddField hpc_target, reference, visibility 0002_flowproject_visibility + 0003_flowproject_reference_hpc_target
0005_merge_20260524_1609 (empty merge)

98af506a does not change models.py, so these are not migrations for a new model change — they are duplicates of what the snapshot already builds (the 0005_merge is a leftover makemigrations --merge artifact). Startup runs migrate only, so the redundant ops execute against the schema 0001_initial already created → DuplicateColumn.

Fix

Delete the 4 redundant migrations, leaving the consistent chain:

0001_initial → 0002_flowproject_visibility → 0003_flowproject_reference_hpc_target

which reproduces the current models.py schema exactly (workflow_context, visibility, reference, hpc_target, WorkflowRun); 0003_flowproject_reference_hpc_target already uses ADD COLUMN IF NOT EXISTS.

No data migration is needed: on databases that already applied the redundant migrations the deleted records become harmless phantom entries, and migrate resolves the remaining single-leaf graph without error.

Verification

Ran migrate against a brand-new empty database with this branch's code:

Applying workflow.0001_initial... OK
Applying workflow.0002_flowproject_visibility... OK
Applying workflow.0003_flowproject_reference_hpc_target... OK

No DuplicateColumn, no crash loop. (Before this change, the same fresh-DB migrate fails at 0002_flowproject_workflow_context.)

Notes / follow-ups

  • The box app has an analogous redundancy (00020005 alter_pythonfile_category), but those are AlterField ops that don't break migrate — left out of scope here as a follow-up cleanup.
  • Prevention: the repo has no CI. Since pytest/pytest-django builds its test DB by running migrations, a minimal CI job running the backend test suite against a fresh Postgres would catch this class of bug automatically. Recommended as a separate task.

…-DB migrate

The regenerated `0001_initial` snapshot (commit 8d9fdb2) already creates
`FlowProject.workflow_context` and the `WorkflowRun` model. PR #55 later added a
parallel branch of locally auto-generated migrations
(`0002_flowproject_workflow_context`, `0003_workflowrun`,
`0004_flowproject_hpc_target_flowproject_reference_and_more`,
`0005_merge_20260524_1609`) that re-apply the same schema. On a fresh database
`migrate` fails with `column "workflow_context" of relation "flow_projects"
already exists`, so the backend crash-loops on startup.

Remove the 4 redundant migrations, leaving the consistent chain
`0001_initial -> 0002_flowproject_visibility -> 0003_flowproject_reference_hpc_target`,
which reproduces the current models.py schema exactly. No data migration is needed:
on already-migrated databases the deleted records become harmless phantom entries.

Verified: `migrate` against a brand-new empty database applies all three workflow
migrations cleanly with no DuplicateColumn error.

Fixes #65

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 23, 2026 17:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes a redundant/duplicated branch of Django migrations in the workflow app that caused manage.py migrate to fail on a fresh database due to duplicate schema operations (e.g., workflow_context already existing), restoring a single consistent migration chain.

Changes:

  • Deleted duplicate workflow migrations that re-applied schema already created by 0001_initial.
  • Removed an empty merge migration that only existed to reconcile the duplicated migration branches.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
gui/workflow_backend/django-project/app/workflow/migrations/0002_flowproject_workflow_context.py Deleted redundant migration that re-added FlowProject.workflow_context already present in 0001_initial.
gui/workflow_backend/django-project/app/workflow/migrations/0003_workflowrun.py Deleted redundant migration that re-created WorkflowRun already present in 0001_initial.
gui/workflow_backend/django-project/app/workflow/migrations/0004_flowproject_hpc_target_flowproject_reference_and_more.py Deleted redundant migration that re-added fields already covered by the remaining migration chain.
gui/workflow_backend/django-project/app/workflow/migrations/0005_merge_20260524_1609.py Deleted empty merge migration that only existed due to the duplicated branch.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@IzBrain67
IzBrain67 merged commit 5fecf70 into main Jun 23, 2026
1 check passed
@IzBrain67
IzBrain67 deleted the fix/workflow-migration-redundancy branch June 23, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fresh-DB migrate fails: workflow migrations are internally inconsistent (duplicate workflow_context / WorkflowRun)

2 participants