[#484] Apply SQLite schema without the native Prisma schema-engine#485
Conversation
…PIC #465) The packed prod-only start smoke still failed on the operator's macOS arm64: startup `prisma db push` exited with an empty "Schema engine error:". Root cause — `db push` spawns the native Prisma *schema-engine* binary, which fails to start in some packed prod-only installs. #479 had made the CLI *resolution* robust, but the schema-engine itself is the fragile, platform-specific piece. Fix: stop invoking the schema-engine at runtime. Ship the canonical DDL as app/prisma/schema.sql (generated from schema.prisma) and apply it at startup through the Prisma client's library QUERY engine via $executeRawUnsafe — the same engine the app already uses for every query, so if the app runs at all, schema setup runs too. Statements are CREATE TABLE/INDEX IF NOT EXISTS, so it's idempotent on every boot. - app/lib/apply-schema.ts (+test): parse/idempotency helpers + loadSchemaStatements. - app/prisma/schema.sql: committed DDL; scripts/gen-schema-sql.mjs + `npm run prisma:sql` regenerate it (schema-engine used at DEV time only). - app/server.ts: apply schema.sql via the client; no child-process shell-out. - Remove now-unused app/lib/prisma-cli.ts (+test); supersede its pack-hygiene entry with apply-schema.ts + schema.sql. - Regression coverage: model→table sync test, idempotency tests, and a source contract asserting startup never runs `db push` (the Linux smoke can't catch a schema-engine regression since its engine works). Proven: in a packed --omit=dev install with the schema-engine binary DELETED, the app still boots and serves /api/auth/status (old `db push` would fail there). No dependency-hygiene change (allowlist still 11; prisma stays for postinstall generate). Verified Node 20.20.2 / npm 10.8.2: typecheck, test (1261), app:build, preflight (0/0, packed start smoke green), npm audit --omit=dev clean. Version 1.2.93 -> 1.2.94. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
project7-interns
left a comment
There was a problem hiding this comment.
Verdict: APPROVE
Summary
PR #485 satisfies #484. It removes the runtime dependency on Prisma schema-engine startup by applying committed SQLite DDL through Prisma Client, while preserving the production dependency boundary and packed start-smoke coverage.
Findings
- No blocking findings.
Decision
Approved at b565d52f33ccdc1196d2a7789f5056b571c6cb01, pending green CI. I reviewed the live PR diff, issue #484, and live checks. The startup path no longer invokes prisma db push or shells out for database setup; app/server.ts connects Prisma Client, loads app/prisma/schema.sql, and applies idempotent CREATE TABLE/INDEX IF NOT EXISTS statements through $executeRawUnsafe. The packed runtime now explicitly requires app/lib/apply-schema.ts and app/prisma/schema.sql, while React, Vite, AWS/S3, and other build/web deps remain out of runtime dependencies. Regression coverage locks the parser/idempotency behavior, committed DDL model coverage, package contents, and the no-db push startup contract. Live lint-and-typecheck was still pending when reviewed. Local tests were not run in this checkout.
|
@re2 APPROVE — #484 correctly fixes the schema-engine startup failure. Well-engineered with decisive proof. Reviewed the PR commit (
Two NON-BLOCKING, forward-looking notes (schema-evolution, not this PR's scope — current Session/Setting schema is unaffected):
No blocking findings. Note for @Head: CI |
#484 — Fix packed prod-only Prisma schema-engine startup failure
Follow-up for EPIC #465; unblocks operator gate #472. Builds on #479 (PR #480) and #481 (PR #483) — does not revert either.
Root cause
Even after #479/#481, the operator's final verification on
main1.2.93 (Node 20.20.2 / npm 10.8.2, macOS arm64) failed in the packed start smoke: startupprisma db pushexited with an emptySchema engine error:before/api/auth/statusserved.prisma db pushspawns the native Prisma schema-engine — a separate, platform-specific binary (@prisma/engines/schema-engine-*). That binary fails to start in some packed prod-only installs (empty error on macOS arm64). #479 made the CLI resolution robust, but the schema-engine itself is the fragile piece, and it only runsdb push. (This is why the Linux start smoke went green for #479/#481 — Linux's schema-engine works.)Fix — stop using the schema-engine at runtime
The app's normal operation uses the Prisma client's library query engine (a different, reliably-present engine — if it failed, the app couldn't serve anything). So we let it set up the schema instead of the schema-engine:
app/prisma/schema.sql(new, committed): the canonical DDL generated fromschema.prisma. Regenerate withnpm run prisma:sql(scripts/gen-schema-sql.mjs) — that uses the schema-engine at dev/build time only, never at user runtime.app/lib/apply-schema.ts(new):parseSqlStatements/makeIdempotent/loadSchemaStatements— reads the DDL and rewrites eachCREATE TABLE/INDEXtoIF NOT EXISTS(idempotent on every boot).app/server.ts: connect the client, then apply the DDL viadb.$executeRawUnsafe(...). Noprisma db push, no child-process shell-out for DB setup. Keeps the HOME-redacted diagnostic + exit 1.app/lib/prisma-cli.ts(+test): the runtime no longer invokes any Prisma binary, which strictly supersedes Fix packed tarball startup smoke failing at Prisma db push #479's CLI-resolution (it does not reintroduce thenpxnetwork/cwd bug Fix packed tarball startup smoke failing at Prisma db push #479 fixed). Pack-hygiene allowlist swaps that entry forapp/lib/apply-schema.ts+app/prisma/schema.sql.Proof it removes the schema-engine dependency
Beyond preflight passing, I ran a decisive check: in a packed
--omit=devinstall I deleted the schema-engine binary (@prisma/engines/schema-engine-debian-openssl-3.0.x, the only one present) and started the bin with a fresh HOME — the app still booted and served/api/auth/status. The oldprisma db pushpath would fail there (that's the operator's exact symptom). Platform-independent fix confirmed.Regression coverage
apply-schema.modelinschema.prismahas aCREATE TABLEinschema.sql(catches a schema change that forgotnpm run prisma:sql).app/server.tsappliesschema.sqland never runsdb push/execSync— because the Linux start smoke passes either way, this is what locks the fix against a schema-engine regression.Boundary preserved
Runtime
dependenciesallowlist unchanged (still 11;prismastays for the postinstallprisma generate, which uses the query engine and already works). No React/Vite/AWS/S3/build deps added. No wallet/publish/dashboard/fiction/cartoon/agent-session/web-UI behavior changed.Verification (Node 20.20.2 / npm 10.8.2)
npm run typecheck— passnpm test— pass (1261; +7 net)npm run app:build— pass (committed dist unchanged)npm run preflight— pass, 0 warnings / 0 failures (packed start smoke boots + serves/api/auth/status+/)npm audit --omit=dev— 0 vulnerabilitiesVersion 1.2.93 → 1.2.94.
Acceptance mapping (#484)
npm audit --omit=devclean🤖 Generated with Claude Code