Repository navigation
chore: add migration check GitHub Action - #9847
Conversation
◈ PR Lens
Architecture 1 component touched across 3 lanes. Data flow
View
Tip The diagrams are links. Click one to open it on the canvas, then press W or click play to walk through the change. 🪧 More tips
Thanks for using PR Lens! It's built by Coldtea, free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughAdds a GitHub Actions workflow that validates Django migrations for selected pull requests and manual runs. It checks migration consistency and rejects changes to existing migrations unless the pull request has the override label. ChangesMigration validation
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~15 minutes Change: Other Sequence Diagram(s)sequenceDiagram
participant PullRequest
participant GitHubActions
participant Django
participant MigrationHistory
PullRequest->>GitHubActions: Trigger migration-check workflow
GitHubActions->>Django: Run system checks and makemigrations --check --dry-run
Django-->>GitHubActions: Return validation result
GitHubActions->>MigrationHistory: Compare base and PR migration files
MigrationHistory-->>GitHubActions: Return migration history result
Merge Risk: ⚪ Minimal · up to The migration validation workflow is mergeable based on the available evidence. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🟡 Changes recommended
The “already-merged migration guard” pathspec does not match the repository’s migration directory structure, so the guard will not detect touched migrations as intended.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds a dedicated GitHub Actions workflow to validate Django migrations in apps/api at PR time, aiming to prevent post-merge migration graph issues and protect already-applied migration history.
Changes:
- Introduces
.github/workflows/migration-check.ymltriggered on PRs intopreview,canary, andmaster(plus manual runs). - Runs
python manage.py checkandpython manage.py makemigrations --check --dry-rununderplane.settings.production. - Adds a guard step intended to fail PRs that modify/delete/rename migrations that already exist on the base branch (unless an override label is present).
File summaries
| File | Description |
|---|---|
| .github/workflows/migration-check.yml | New CI workflow to validate migration graph consistency and guard against rewriting already-merged migrations |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| - name: Guard already-merged migrations | ||
| if: github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'migration-history-override') | ||
| run: | | ||
| TOUCHED=$(git diff --name-status --diff-filter=MDR HEAD^1 HEAD -- 'apps/api/*/migrations/*.py') |
Backport of upstream makeplane/plane d8dc816 (makeplane#9847) and f6a136f (makeplane#10189). The makemigrations override keeps apps/api/migrations_lockfile.txt naming the latest migration of every app, so two pull requests that each add a migration to the same app conflict in Git instead of both merging. Adapted for Hangar: - The lockfile lists Hangar's leaves: db 0136, ext 0039 (the fork-only app) and license 0024, regenerated with makemigrations. - The lockfile test also checks the committed lockfile against the real migration graph, that every app has one leaf, and that no two migrations of an app share a number, so upstream migrations that Hangar carries under its own numbers cannot come back with a sync. - The workflow installs requirements.txt with pip instead of uv, pins actions to commits, does not keep the checkout token, passes base_ref through env, targets preview only, and drops upstream's labelling job with its pull-requests: write token.
Description
Adds
.github/workflows/migration-check.yml, a CI job that fails a PR whose migrations would break once merged into the base branch.Three checks, all against
apps/api:python manage.py check— Django system checks.python manage.py makemigrations --check --dry-run— fails on conflicting leaf nodes (the PR and the base branch both numbered a migration off the same parent), on a dependency pointing at a migration that does not exist, and on model changes never written to a migration. Note thatmanage.py checkalone does not catch any of these, which is why both steps are here.makemigrations --checkstays silent, but every environment that already applied the old file is left with adjango_migrationsrow that no longer resolves. Overridable with amigration-history-overridelabel for deliberate rewrites where nothing has applied the old file.The guard's pathspec
apps/api/*/migrations/*.pycovers both migration trees in this repo —plane/dbandplane/license(130 files at time of writing).Implementation notes:
pull_request,actions/checkoutchecks outrefs/pull/N/merge— the PR already merged into the base branch — so the migration graph being validated is the post-merge one, which is the case this is meant to catch. That also makesHEAD^1the base tip andHEAD^2the PR head, so the guard's diff needs onlyfetch-depth: 2rather than a full clone of this monorepo.makemigrationsemits aRuntimeWarningabout the unreachable connection and still exits correctly.SECRET_KEY,REDIS_URLandDATABASE_URLare set to parse-only placeholders (plane/celery.pybuilds a Redis client fromREDIS_URLat import time).plane.settings.productionand installsapps/api/requirements.txt, matching how the app actually boots in deployment. No extra system packages are needed —Build and lint APIalready installs the same requirements onubuntu-latest/ Python 3.12 today,psycopg-cincluded.apps/api/requirements/*.txtrather than the rootapps/api/requirements.txt, since the latter is only a-r requirements/production.txtpointer and never changes when a dependency is bumped.preview,canaryandmaster, only onapps/api/**changes (plus the workflow file itself), skips drafts, and cancels superseded runs.Deliberately not included: running
manage.py migrateagainst a Postgres service container. It would additionally catch brokenRunPython/ SQL that a static graph check cannot, at the cost of a service container and several minutes per run. Worth adding if a migration ever fails at deploy time rather than at parse time.Type of Change
Screenshots and Media (if applicable)
Test Scenarios
Verified locally against the current
previewtree (Python 3.12, Django 5.2.15), withDATABASE_URLandREDIS_URLpointed at dead ports to confirm no services are needed:manage.py check→System check identified no issues (0 silenced)., exit 0.manage.py makemigrations --check --dry-run→No changes detected, exit 0 (only the expectedRuntimeWarningabout the unreachable connection).0122_*migration inplane/db/migrationsdepending on the same0121_alter_estimate_typeparent, reproducing the post-merge collision:makemigrations --checkexits 1 withCommandError: Conflicting migrations detected; multiple leaf nodes in the migration graph: (0122_alter_draftissue_assignees_alter_issue_assignees_and_more, 0122_zz_fake_conflict in db).manage.py checkexits 0 on the same tree, confirming it does not cover this.git diff --name-status --diff-filter=MDRrun against real history in this repo: fires onf7d5200ed89(modified the existingplane/db/migrations/0113_webhook_version.py), silent onca3b48ef871and9fa707b2607(added migrations only).actionlinton the new workflow: clean.To verify in CI:
apps/api/**that only adds a new migration — the job should pass.migration-history-overridelabel is added.preview, then push a PR whose migration was numbered off the pre-merge parent —makemigrations --checkshould fail on the two leaf nodes even though the branch alone is consistent.References
None.
🤖 Generated with Claude Code
Summary by CodeRabbit