Skip to content

Verify Prisma 7 against a live database before scheduling the migration (P2002 mapping + migrate deploy on a deployed DB) #186

Open

Description

@JonasBaeumer

Blocks #182. This is the prerequisite that has to be answered before the
Prisma 7 migration can be scheduled with any confidence.

The migration change set itself is already written and verified green
(see the investigation on #182): 6 files, ~20 lines, prisma generate
succeeds, tsc clean, 38 suites / 412 tests pass. What could not be
verified is anything requiring a real Postgres — no Docker or local
psql was available.

Two questions, both of which need a live database.

1. Does P2002 still map through the pg driver adapter?

Prisma 7 replaces Prisma's Rust query engine connection with a node-postgres
driver adapter. Error codes are known to shift at the edges — a connection
failure now surfaces as PrismaClientKnownRequestError with
code = 'ECONNREFUSED' where Prisma 5 gave PrismaClientInitializationError
/ P1001.

The codebase branches on exactly three codes:

Code Site
P2002 unique constraint src/telegram/signupHandler.ts:188
P2025 record not found src/payments/providerFactory.ts:53, src/api/routes/agent.ts:208

P2002 is the one that matters. If unique-constraint violations no longer
surface as P2002 through the adapter, signupHandler.ts:188 stops matching
and the Telegram signup flow silently rethrows instead of showing
"email already exists". That is a user-facing regression that no unit test
catches, because every unit test mocks @/db/client.

How to settle it: against a real Postgres, insert a duplicate on a unique
column and assert the thrown error is PrismaClientKnownRequestError with
code === 'P2002'. Worth keeping as a permanent integration test either way.

2. Does migrate deploy work against an already-deployed database?

The 15 migrations in prisma/migrations/ are untouched by the change, and
prisma migrate diff --from-empty emits correct SQL, so the datamodel still
translates. migrate deploy and migrate status both resolve the URL from
prisma.config.ts, load the schema and reach the connect stage — failing only
on P1001: Can't reach database server, which at least confirms the config
wiring is right.

What is unverified is the part that actually carries risk: whether the
_prisma_migrations table written by Prisma 5 is readable by the Prisma 7
engine on an existing deployed database. Checksum and format drift across
major versions is the classic upgrade hazard, and it does not show up against
a fresh database.

How to settle it: run npx prisma migrate deploy against a restored copy
of the deployed database, not a fresh one. CI's integration job already covers
the fresh-database case automatically on the first PR run — that half needs no
extra work.

Why this is separate from #182

#182 is the migration. This is the decision input. The migration has been
deliberately deferred — nothing depends on it, main is green on Prisma 5,
and no security driver was found. It should be scheduled only once these two
answers are known, because #1 in particular determines whether the change is
a half-day or a half-day plus a user-facing bug hunt.

Acceptance

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions