Skip to content

chore: add migration check GitHub Action - #9847

Merged
sriramveeraghanta merged 1 commit into
previewfrom
chore/api-migration-check-ci
Sep 16, 2026
Merged

sriramveeraghanta merged 1 commit into
previewfrom
chore/api-migration-check-ci

Conversation

@sriramveeraghanta

@sriramveeraghanta sriramveeraghanta commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

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 that manage.py check alone does not catch any of these, which is why both steps are here.
  • Already-merged migration guard — fails if the PR modifies, deletes or renames a migration file that already exists on the base branch. The graph stays valid in that case, so makemigrations --check stays silent, but every environment that already applied the old file is left with a django_migrations row that no longer resolves. Overridable with a migration-history-override label for deliberate rewrites where nothing has applied the old file.

The guard's pathspec apps/api/*/migrations/*.py covers both migration trees in this repo — plane/db and plane/license (130 files at time of writing).

Implementation notes:

  • On pull_request, actions/checkout checks out refs/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 makes HEAD^1 the base tip and HEAD^2 the PR head, so the guard's diff needs only fetch-depth: 2 rather than a full clone of this monorepo.
  • No database or Redis service is required: both Django commands read the migration graph off disk. makemigrations emits a RuntimeWarning about the unreachable connection and still exits correctly. SECRET_KEY, REDIS_URL and DATABASE_URL are set to parse-only placeholders (plane/celery.py builds a Redis client from REDIS_URL at import time).
  • Runs under plane.settings.production and installs apps/api/requirements.txt, matching how the app actually boots in deployment. No extra system packages are needed — Build and lint API already installs the same requirements on ubuntu-latest / Python 3.12 today, psycopg-c included.
  • Caches pip on apps/api/requirements/*.txt rather than the root apps/api/requirements.txt, since the latter is only a -r requirements/production.txt pointer and never changes when a dependency is bumped.
  • Triggers on PRs into preview, canary and master, only on apps/api/** changes (plus the workflow file itself), skips drafts, and cancels superseded runs.

Deliberately not included: running manage.py migrate against a Postgres service container. It would additionally catch broken RunPython / 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

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

Test Scenarios

Verified locally against the current preview tree (Python 3.12, Django 5.2.15), with DATABASE_URL and REDIS_URL pointed 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 expected RuntimeWarning about the unreachable connection).
  • Planted a second 0122_* migration in plane/db/migrations depending on the same 0121_alter_estimate_type parent, reproducing the post-merge collision: makemigrations --check exits 1 with CommandError: 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 check exits 0 on the same tree, confirming it does not cover this.
  • Guard step's git diff --name-status --diff-filter=MDR run against real history in this repo: fires on f7d5200ed89 (modified the existing plane/db/migrations/0113_webhook_version.py), silent on ca3b48ef871 and 9fa707b2607 (added migrations only).
  • actionlint on the new workflow: clean.

To verify in CI:

  1. Open a PR touching apps/api/** that only adds a new migration — the job should pass.
  2. Open a PR that edits an existing migration file — the guard should fail with the offending paths, and pass once the migration-history-override label is added.
  3. Merge a migration to preview, then push a PR whose migration was numbered off the pre-merge parent — makemigrations --check should fail on the two leaf nodes even though the branch alone is consistent.

References

None.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Added automated migration validation for eligible pull requests and manual runs.
    • Checks for model and migration inconsistencies, migration graph issues, and unexpected changes to existing migrations.
    • Skips draft pull requests and supports canceling redundant runs per branch.

Copilot AI lite review requested due to automatic review settings September 16, 2026 19:33
@coldtea-pr-lens

coldtea-pr-lens Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

◈ PR Lens

🟢 +1 new · 🟠 ~0 changed · 🔴 -0 removed · 1 flow · 1 file · commit 5226110


Architecture

Architecture diagram for makeplane/plane at 5226110

1 component touched across 3 lanes.

Open the interactive canvas


Data flow

Data flow diagram for makeplane/plane at 5226110

Validating migrations in CI

Open the interactive canvas


View

  • Architecture lens
  • Data flow lens
  • Expand every detail

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
  • Run npx skills add coldteadotai/pr-lens, then tell your coding agent: "Diagram the change you just made with PR Lens and attach it to the pull request."
  • Run npx @coldtea/pr-lens-cli analyze --base origin/main on a branch, then npx @coldtea/pr-lens-cli render .pr-lens/graph.json. Same lenses, your own model key, before the pull request exists.
  • Untick Architecture lens or Data flow lens under View to hide a diagram, or tick Expand every detail to open every section. The comment redraws in a few seconds.
  • Click the link under each diagram to open it on a canvas you can zoom, pan and step through.
  • Open a diagram on the canvas, then press W or click play to walk through the change one step at a time.
  • The CLI's render reads .github/pr-lens.yml and applies your renames, exclusions and lane pins at draw time.
  • Set github.comment.collapsed: true in .github/pr-lens.yml to fold the comment behind one View architecture and data flow row. Drawing still runs on every push.
  • Add .github/workflows/pr-lens.yml with coldteadotai/pr-lens/packages/action@v0 and your model provider's key as its api-key to run PR Lens from your own CI. Any /chat/completions endpoint works.
  • Push a commit and the comment redraws for the new head. A slow older run never overwrites a newer one.
  • Switch GitHub to dark mode and the diagrams follow. The moving dots are this pull request's data in motion.

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.

❤️ Share

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 3014f65b-2203-4aff-b529-ef844a9bdc42

📥 Commits

Reviewing files that changed from the base of the PR and between a896115 and 5226110.

📒 Files selected for processing (1)
  • .github/workflows/migration-check.yml

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Adds 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.

Changes

Migration validation

Layer / File(s) Summary
Workflow triggers and execution setup
.github/workflows/migration-check.yml
The workflow runs for selected pull request changes or manual dispatches. It skips draft pull requests, cancels obsolete branch runs, uses read-only permissions, configures Python 3.12, and installs API dependencies.
Migration validation and history guards
.github/workflows/migration-check.yml
The job runs Django system checks and dry-run migration checks. For pull requests without migration-history-override, it rejects modified, deleted, or renamed existing migrations.

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
Loading

Merge Risk: ⚪ Minimal · up to 52261

The migration validation workflow is mergeable based on the available evidence.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding a GitHub Actions migration check.
Description check ✅ Passed The description includes all required sections, explains the workflow behavior and scope, identifies the change type, documents detailed test scenarios, and states that there are no references.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/api-migration-check-ci

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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.yml triggered on PRs into preview, canary, and master (plus manual runs).
  • Runs python manage.py check and python manage.py makemigrations --check --dry-run under plane.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')
@sriramveeraghanta
sriramveeraghanta merged commit d8dc816 into preview Sep 16, 2026
18 checks passed
@sriramveeraghanta
sriramveeraghanta deleted the chore/api-migration-check-ci branch September 16, 2026 19:54
nettnikl pushed a commit to nettnikl/hangar that referenced this pull request Dec 1, 2026
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.
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.

3 participants