Skip to content

fix(prisma): report real migration counts instead of 0 applied, 0 pending - #3566

Closed
WoldenMn wants to merge 1 commit into
rtk-ai:developfrom
WoldenMn:fix/prisma-migrate-status-zero-counts
Closed

WoldenMn wants to merge 1 commit into
rtk-ai:developfrom
WoldenMn:fix/prisma-migrate-status-zero-counts

Conversation

@WoldenMn

Copy link
Copy Markdown

Problem

rtk prisma migrate status reports Migrations: 0 applied, 0 pending against a database that has migrations applied.

Reproduced on Prisma 7.8.0 + PostgreSQL 16, in a real project (6 migrations) and in an isolated throwaway project (2 migrations):

$ npx prisma migrate status
6 migrations found in prisma/migrations
Database schema is up to date!

$ rtk prisma migrate status
Migrations: 0 applied, 0 pending

filter_migrate_status counts lines containing the substring applied:

if line.contains("applied") { applied_count += 1; ... }
if line.contains("pending") || line.contains("unapplied") { pending_count += 1; }

Prisma does not print either word on a successful run — it prints N migrations found in <path> and Database schema is up to date!. This is not a Prisma 7 regression: no Prisma version emits the shape this counter expects, so the summary has always been 0 applied, 0 pending on a healthy database.

Two related consequences of the same heuristic:

  • Following migration have not yet been applied: contains applied, so a pending migration is scored as an applied one.
  • filter_migrate_deploy reported 2 migration(s) deployed for a run that applied three, having counted the two summary sentences instead of the per-migration Applying migration \name`` lines.

Scope, measured rather than assumed: the filter only runs on success, and Prisma exits 1 when migrations are pending, so rtk falls through to raw passthrough in that case and the pending migration stays visible. Exit codes are propagated correctly. The damage is a confidently wrong count, not a hidden pending migration — but a count of 0 on a healthy project is the kind of output an agent will quote as fact.

never_worse cannot help here: it compares token counts, never correctness.

Fix

Parse the documented output shapes, and fall back to the raw output whenever the text does not match one of them — drift, failed migrations, shadow-database errors. A summary that cannot be trusted is worse than no summary.

$ rtk prisma migrate status
3 migration(s) found, schema up to date

# with a migration that has not been applied yet
4 migration(s) found, 1 not yet applied:
  - 20260401000000_add_flange

# deploy
3 migration(s) applied:
  - 20260101000000_init
  - 20260201000000_add_gadget
  - 20260301000000_add_sprocket

Tests

10 new tests. Fixtures are verbatim captures from Prisma 7.8.0 against PostgreSQL 16, not hand-written approximations. Two of them are explicit regression guards:

  • status_never_claims_zero_when_migrations_exist
  • status_does_not_count_the_pending_header_as_applied

Both were confirmed non-vacuous by mutation: forcing the count back to 0 makes them fail, and reverting makes them pass.

cargo test prisma   ->  16 passed; 0 failed
cargo fmt -- --check ->  clean
cargo clippy --all-targets -> no warnings

cargo test on the full crate is 2583 passed; 3 failed. The three failures are in hooks::rewrite_cmd::tests::unattestable_passthrough and are pre-existing on develop (6f0b0ca) — verified by stashing this patch and re-running, and by moving %APPDATA%\rtk\config.toml aside to rule out local config. They are unrelated to this change; happy to open a separate issue if they are not already known.

Environment: Windows 11, stable-x86_64-pc-windows-msvc.

`rtk prisma migrate status` printed "Migrations: 0 applied, 0 pending"
against a database with six applied migrations, and the same summary
would appear for a project with none. filter_migrate_status counted
lines containing the substring "applied", which Prisma does not print
on a successful run: it prints "N migrations found in <path>" followed
by "Database schema is up to date!". No Prisma version emits the shape
that counter expects.

Two more consequences of the same heuristic:

- "Following migration have not yet been applied:" contains "applied",
  so a pending migration was scored as an applied one.
- filter_migrate_deploy reported "2 migration(s) deployed" for a run
  that applied three, having counted the two summary sentences rather
  than the per-migration "Applying migration `name`" lines.

Parse the documented output shapes instead, and return the raw output
whenever the text does not match one of them (drift, failed migrations,
shadow database errors). A status summary that cannot be trusted is
worse than no summary at all: never_worse compares sizes only, so it
cannot catch a parser that is confidently wrong.

Test fixtures are verbatim captures from Prisma 7.8.0 against
PostgreSQL 16, not hand-written approximations.

Co-Authored-By: Claude Opus 5 <[email protected]>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@pszymkowiak

Copy link
Copy Markdown
Collaborator

Thanks for the contribution! Before we can review and merge this, the CLA needs to be signed. The CLAassistant bot left the link above, it only takes a minute. Once it's signed we'll pick the review up.

@KuSh KuSh added the needs-cla label Oct 31, 2026
@WoldenMn WoldenMn closed this by deleting the head repository Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants