Skip to content

test: out-of-order migration (DO NOT MERGE) - #1401

Closed
brendan-kellam wants to merge 8 commits into
mainfrom
brendan-kellam/test-out-of-order-migration
Closed

test: out-of-order migration (DO NOT MERGE)#1401
brendan-kellam wants to merge 8 commits into
mainfrom
brendan-kellam/test-out-of-order-migration

Conversation

@brendan-kellam

@brendan-kellam brendan-kellam commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

DO NOT MERGE — test PR.

Branched off brendan-kellam/enforce-prisma-migration-order (so it carries the new PR Gate migration check + composite action) and adds a no-op migration timestamped 20200101000000, earlier than the latest migration on main.

Expected: the PR Gate → Check Prisma migrations step fails at the ordering check with:

❌ New migration 20200101000000 predates latest migration on main (...). Rename it with a current timestamp.

The drift check should pass (the migration is a no-op SELECT 1;), so this isolates the ordering check.

Delete this branch/PR once the check is verified.

Summary by CodeRabbit

  • Chores
    • Added a no-op database migration for validation checks.
    • This change does not affect app behavior or existing data.

brendan-kellam and others added 5 commits June 29, 2026 16:03
Add a GitHub Actions workflow that runs on PRs touching
packages/db/prisma/**. It verifies migrations apply cleanly in
sequence and reproduce schema.prisma (drift check via prisma
migrate diff), and that no newly added migration predates the
latest migration on main (out-of-order timestamp check).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Replace the standalone migration workflow with a composite action
(.github/actions/check-prisma-migrations) and embed it in:
- pr-gate.yml's build job, so migration drift or out-of-order
  timestamps fail the required PR check before merge.
- _build.yml's build job (amd64 only) as a release-time backstop
  for schema drift.

The action self-contains Postgres via docker run, detects whether
Prisma files changed (skipping fast on PRs that don't), verifies
migrations apply in sequence and reproduce schema.prisma, and
checks no new migration predates the latest on the base branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
DO NOT MERGE. No-op migration timestamped 2020-01-01, earlier than
the latest migration on main, to verify the ordering check fails.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

@brendan-kellam your pull request is missing a changelog!

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b44ac277-c049-4ef9-9b90-bd6570eb4714

📥 Commits

Reviewing files that changed from the base of the PR and between e0ec675 and f074eb1.

📒 Files selected for processing (1)
  • packages/db/prisma/migrations/20260629193001_dummy_out_of_order/migration.sql
💤 Files with no reviewable changes (1)
  • packages/db/prisma/migrations/20260629193001_dummy_out_of_order/migration.sql

Walkthrough

A new Prisma migration SQL file is added as a no-op dummy (SELECT 1;) with an intentionally earlier timestamp to serve as a CI test fixture for out-of-order migration detection.

Changes

Dummy Out-of-Order Migration Fixture

Layer / File(s) Summary
No-op dummy migration SQL
packages/db/prisma/migrations/20260629193001_dummy_out_of_order/migration.sql
Adds a dummy migration containing only comments explaining its CI purpose and a SELECT 1; no-op statement, with a timestamp designed to trigger out-of-order detection.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

  • sourcebot-dev/sourcebot#1400: Introduces the prisma-migrations.yml workflow with the out-of-order migration ordering check that this dummy fixture is intended to validate.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the test-only out-of-order migration change and its intent.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 brendan-kellam/test-out-of-order-migration

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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/actions/check-prisma-migrations/action.yml:
- Around line 71-77: The current Prisma migration check only runs migrate deploy
via the Apply migrations step, so it misses edited, renamed, or deleted
migration history under packages/db/prisma/migrations. Update the
check-prisma-migrations workflow to explicitly fail on any non-addition in that
migrations tree, while keeping the existing timestamp validation for newly added
migration folders; use the existing migration-detection logic and the Apply
migrations step as the place to enforce the rejection.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a35e86cb-953d-4bd4-b11d-056d2e1663da

📥 Commits

Reviewing files that changed from the base of the PR and between c40f931 and e0ec675.

📒 Files selected for processing (4)
  • .github/actions/check-prisma-migrations/action.yml
  • .github/workflows/_build.yml
  • .github/workflows/pr-gate.yml
  • packages/db/prisma/migrations/20200101000000_dummy_out_of_order/migration.sql

@coderabbitai coderabbitai Bot 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.

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/actions/check-prisma-migrations/action.yml:
- Around line 71-77: The current Prisma migration check only runs migrate deploy
via the Apply migrations step, so it misses edited, renamed, or deleted
migration history under packages/db/prisma/migrations. Update the
check-prisma-migrations workflow to explicitly fail on any non-addition in that
migrations tree, while keeping the existing timestamp validation for newly added
migration folders; use the existing migration-detection logic and the Apply
migrations step as the place to enforce the rejection.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a35e86cb-953d-4bd4-b11d-056d2e1663da

📥 Commits

Reviewing files that changed from the base of the PR and between c40f931 and e0ec675.

📒 Files selected for processing (4)
  • .github/actions/check-prisma-migrations/action.yml
  • .github/workflows/_build.yml
  • .github/workflows/pr-gate.yml
  • packages/db/prisma/migrations/20200101000000_dummy_out_of_order/migration.sql
🛑 Comments failed to post (1)
.github/actions/check-prisma-migrations/action.yml (1)

71-77: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Does prisma migrate deploy fail when a previously applied migration file or folder has been modified or renamed, and how does Prisma validate migration checksums/history?

💡 Result:

The command prisma migrate deploy does not fail if a previously applied migration file has been modified or renamed; instead, it proceeds with the deployment while issuing a warning [1][2]. Prisma Migrate validates migration history using a checksum mechanism stored in the _prisma_migrations table in your database [3][4]. Mechanism details: - Validation: Prisma calculates the SHA-256 checksum of the migration files present in your prisma/migrations folder and compares them against the checksums recorded in the _prisma_migrations table for every migration that was previously applied [3][5]. - Behavior on modification: If the content of a migration file is altered (even by reformatting or adding comments), the calculated checksum will no longer match the one in the database [2][3]. When prisma migrate deploy detects this discrepancy, it triggers a warning message informing you that the migration has been modified since it was applied, but the command itself does not stop or fail [1][2]. - Renaming: Renaming a migration folder or file disrupts the identity of that migration in the history, as the system relies on the file structure and names to identify which migrations have already been processed [3][6]. It is strongly recommended to maintain the integrity of your migration history. If you modify or rename applied migrations, Prisma will continue to warn you upon every execution of migrate deploy [6]. The official recommendation is to fix the root cause—such as restoring the file to its original state or reverting changes—rather than ignoring these warnings, as they ensure that your production database state remains synchronized with your source-controlled migration history [6].

Citations:


🏁 Script executed:

sed -n '1,180p' .github/actions/check-prisma-migrations/action.yml

Repository: sourcebot-dev/sourcebot

Length of output: 4751


Reject edits to existing Prisma migrations. This job only proves the current tree boots on a fresh database; it won’t catch edited, renamed, or deleted migration history, and Prisma only warns when a previously applied migration changes. Fail the check on any non-addition under packages/db/prisma/migrations, and keep the timestamp check for new folders.

🧰 Tools
🪛 Checkov (3.3.2)

[medium] 76-77: Basic Auth Credentials

(CKV_SECRET_4)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/actions/check-prisma-migrations/action.yml around lines 71 - 77, The
current Prisma migration check only runs migrate deploy via the Apply migrations
step, so it misses edited, renamed, or deleted migration history under
packages/db/prisma/migrations. Update the check-prisma-migrations workflow to
explicitly fail on any non-addition in that migrations tree, while keeping the
existing timestamp validation for newly added migration folders; use the
existing migration-detection logic and the Apply migrations step as the place to
enforce the rejection.

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.

1 participant