Skip to content

Upgrade Prisma to 7.10.1 and make document types accountable #198

Closed

Description

@HMarzban

Goal

Raise @docs.plus/hocuspocus from Prisma 6.19.3 to 7.10.1, by ruling 5 on #575. Make the Prisma schema the only owner of document row types. Keep Zod as the write contract. Keep webapp and admin on wire types only.

Facts (2026-08-27)

  • Pins today: prisma, @prisma/client, and @prisma/adapter-pg at ^6.19.3. Lock resolves 6.19.3.
  • Latest generally available Prisma is 7.10.0 (npm dist-tag prev). 7.10.0 · Upgrade to v7
  • npm latest is Prisma 8 RC (8.0.0-rc.12 on this date). Do not take 8. Pin 7.10.0. Never write prisma@latest. Ruling 5 now pins 7.10.1.
  • The adapter path is already live. src/lib/prisma.ts constructs PrismaPg and passes adapter into PrismaClient.
  • Generator is still prisma-client-js with previewFeatures = ["fullTextSearchPostgres"]. Prisma 7 wants prisma-client, a required output, and prisma.config.ts.
  • Six sites hardcode bunx [email protected]: Docker generate, entrypoint, compose migrate, start-production.ts, and fix-migration.ts. scripts/setup.sh still says 6.19.0. Move them together or boot drifts.
  • Settings search uses { search: } on title, keywords, and description. Confirm that filter after the bump.
  • $on('query'|'error'|'warn' as never, …) is a typing workaround. Re-type it on the v7 client.
  • Root [email protected] exists because Prisma 6's @prisma/config pulled 7.1.5. Drop the pin only after Prisma 7 stays green under bun audit.
  • Inside hocuspocus, production already imports DocumentMetadata from @prisma/client. A hand copy in src/types/document.types.ts omits deletedAt and must go.
  • Zod document.schema.ts is the write contract. keywords is string[] on the wire and String? in Prisma. The service already splits CSV. Keep that transform.
  • Webapp and admin never import @prisma/client. That split stays. fetchDocument.ts lost its [key: string]: any in 633972f69 on 2026-10-19. Its DocumentData type now lists the slug-read fields. VersionTrigger is copied in webapp types/history.ts.
  • DocumentClientAuthor.clientId is BigInt in Prisma and number on the wire. Document that contract. Do not change it silently.
  • DocumentMetadata.email is the one stale cross-store copy. Dropping it is a later change. Not this ticket.
  • Storage design stays: one full Yjs snapshot per version. @@index([documentId]) stays. See apps/hocuspocus.server/CLAUDE.md.
  • Upgrade Bun to 1.4 and measure test plus backend wins #171 already says do not replace Prisma with Bun.SQL. This ticket is the Prisma bump. Upgrade Bun to 1.4 and measure test plus backend wins #171 is not this work.

Backlog row: O8 in BACKLOG-hocuspocus-backend.md.

What to build

One change. Bump and type accountability land together.

  1. Pin prisma, @prisma/client, and @prisma/adapter-pg to 7.10.1. Add prisma.config.ts. Switch the generator. Point every import at the new client output.
  2. Replace every hardcoded bunx [email protected] (and the 6.19.0 setup hint) with the new pin in the same change.
  3. Keep the existing PrismaPg pool. Do not invent a second pool. Strip connection_limit from any URL the CLI migrate path still sees, if 7 rejects it.
  4. Confirm Settings search, persist (a version row), and every P2002 cede still behave. Re-type $on. Re-check Bytes / Uint8Array on FOR UPDATE raw reads.
  5. Delete the hand DocumentMetadata. Use generated Prisma types inside hocuspocus only.
  6. Keep Zod as the only write contract. Deduplicate VersionTrigger so webapp imports the wire union, not a second literal.
  7. Already done: 633972f69 closed fetchDocument.ts's index signature and typed the slug-read DTO. Confirm it still holds after the bump.
  8. Re-check deepmerge-ts after the bump. Keep or drop the pin from bun audit, not from a blog.

Out of scope

  • Prisma 8, including a side-by-side @prisma/prisma7 install.
  • Storage redesign, delta snapshots, or dropping @@index([documentId]).
  • A new workspace types package.
  • Importing @prisma/client into webapp or admin.
  • Dropping DocumentMetadata.email.
  • Replacing Prisma with Bun.SQL (that is a Upgrade Bun to 1.4 and measure test plus backend wins #171 ban).
  • Dynamic slugs.

Acceptance criteria

  • prisma -v and @prisma/client are 7.10.1. git grep -niE 'prisma(@|.*\^)6\.19|Prisma 6\.19' -- . ':!*CHANGELOG*' ':!bun.lock' finds nothing. At HEAD it finds 14 sites, setup.sh and fix-migration.ts included.
  • prisma generate and prisma migrate deploy work locally and in the image. REST on :4000, WS, and worker start.
  • Settings search still returns matches. A pad persist still mints a Documents row. A slug P2002 cede still returns.
  • hocuspocus bun test is green. The store-pipeline or versions e2e that you can run locally is green.
  • No hand DocumentMetadata. Webapp and admin still have zero @prisma/client imports.
  • fetchDocument still has no [key: string]: any (done in 633972f69). VersionTrigger has one source.
  • bun audit result for deepmerge-ts / @prisma/config is recorded. The pin is kept or dropped from that result.

Blocked by

None. Can start immediately. Does not depend on #171 or #172. Do not fold this into the Bun soak.

Activity

  1. added
    enhancement
    dependencies
    on Aug 27, 2026
  2. added this to the v2.3.0 milestone on Oct 24, 2026
  3. changed the title [-]Upgrade Prisma to 7.10.0 and make document types accountable[/-] [+]Upgrade Prisma to 7.10.1 and make document types accountable[/+] on Oct 24, 2026
  4. HMarzban commented on Oct 24, 2026

    @HMarzban
    CollaboratorAuthor

    Update, 2026-10-24: target 7.10.1, and two performance checks

    Version. Prisma 7.10.1 is the newest general release, published on 2026-10-15. It is the latest dist-tag of @prisma/client. The latest dist-tag of the prisma package points at 8.0.0-rc.27, a release candidate. Take 7.10.1 wherever this issue says 7.10.0. Never write prisma@latest. The count of pinned sites has also grown. Move all of these in one change:

    • the three package pins;
    • eight bunx [email protected] sites: apps/hocuspocus.server/docker/Dockerfile.bun:63, :94 and :109, scripts/docker-entrypoint.sh:14, scripts/start-production.ts:11 and :32, scripts/fix-migration.ts:10, and docker-compose.prod.yml:168;
    • two [email protected] lines in apps/hocuspocus.server/scripts/setup.sh:30 and :46.

    Why the upgrade matters for speed. @prisma/[email protected] runs Array.from(new Uint8Array(buffer)) on every bytea value (dist/index.mjs:289). That builds one JS number per stored byte. 7.1.0 still has the copy. 7.2.0, 7.10.0 and 7.10.1 return parsePgBytes directly.

    Measured locally on 2026-10-23, the Prisma bytea read is the main cost in three paths:

    • history.watch. The read is 92.5% of the server time.
    • Cold load. The head read blocks the WS loop about 26–32 ms per stored MB. At 5.36 MB that is 145.6 ms, against 3.7 ms for raw pg.
    • Digest. The fetch peaks at about 977 MB for a 10,521,216 B version pair, against 98 MB for raw pg.

    Array.from alone timed at about 7–9 ms/MB. So the upgrade removes the copy, but maybe not the whole cost. The rest may be the Prisma 6 engine hop.

    New acceptance items.

    • Time the fetch loop block on a 5.36 MB head, before and after the upgrade. Post both numbers here.
    • Record the cgroup fetch peak for the 10,521,216 B digest pair, before and after. Post both numbers here.
    • Record whether ENABLE_SCHEMA_MIGRATION is on in production (Run the production reads that the 2026-10-23 backend perf plan needs #576), because it adds a second decode on cold load.

    Rules that still hold. Keep the existing PrismaPg pool, and do not build a second pg pool. Do not route bytea reads through $queryRaw either, because the adapter parses raw queries too.

    Decisions. Owner: the maintainer (rulings 5 and 6 on #575).

    1. Prisma 8? Recommended: not in this issue. Stay on 7.10.1, and plan 8 in a later milestone after it reaches general release.
    2. Wait for this upgrade, or ship a stopgap on the history.watch and digest reads? The stopgap selects translate(encode(data,'base64'), E'\n', ''), which returns text and skips the adapter's byte conversion. It cut the watch read block from 119.65 ms to 3.69 ms locally. Recommended: wait, because this issue is now in v2.3.0. Decide once for all bytea reads, not read by read.

    This issue is now in milestone v2.3.0, under #575. #214 and #597 wait on it. #593 may change the P2002 cede path first; if it does, re-check its count path here.

  5. HMarzban commented on Oct 24, 2026

    @HMarzban
    CollaboratorAuthor

    Maintainer ruling, 2026-10-24

    Decision 2: wait for this upgrade. Do not ship the base64 stopgap on the history.watch or digest reads. #214 step 1 and #597 wait on this issue.

    Decision 1 (which Prisma version) is still open.

  6. HMarzban commented on Oct 24, 2026

    @HMarzban
    CollaboratorAuthor

    Maintainer ruling, 2026-10-24

    Decision 1: take Prisma 7.10.1 now. Do not take the Prisma 8 release candidate. Prisma 8 moves to #604, after it reaches a stable release.

    Add a before-and-after benchmark. The maintainer needs one table that shows the gain, to report it.

    • Commit one benchmark script, for example apps/hocuspocus.server/scripts/bench-prisma-bytea.ts, so both runs use the same code. Run it on Prisma 6.19.3, then on 7.10.1, on the same machine and fixtures.
    • Measure at least: the cold-load head read loop block on a 5.36 MB head; the history.watch read block on the same head; the cgroup fetch peak for the 10,521,216 B digest pair; and the load and save time of a small, typical document.
    • Use n of 5 or more for each number. Report the median and the spread.
    • Post one table here, with columns for 6.19.3, 7.10.1 and the change in percent. Name the machine, the Bun version and the date.

    Both rulings on this issue are now made. It is unblocked.

  7. HMarzban commented on Oct 25, 2026

    @HMarzban
    CollaboratorAuthor

    Built and committed on local main. Awaits the maintainer's final push.

    Remaining gate: the (build): back deploy, then a check that migrate deploy, REST, WebSocket and the worker all boot on the amd64 host.

  8. HMarzban commented on Nov 3, 2026

    @HMarzban
    CollaboratorAuthor

    Status, 2026-11-03. The Prisma 7.10.1 upgrade shipped in aef96c59a, with follow-ups in d40b265b7 and 7ed40b2f0. It is pushed and deployed. Deploy run 41608014517 passed. Left:

  9. HMarzban commented on Nov 3, 2026

    @HMarzban
    CollaboratorAuthor

    Result, 2026-11-03. Prisma 7.10.1 shipped in aef96c59a, with follow-ups in d40b265b7 and 7ed40b2f0. Deploy run 41608014517 deployed it on 2026-11-03, and every job passed. The ruled bench table is below.

    Local measurement setup (arm64 laptop, 2026-10-25).

    • Machine. Mac17,6, Apple M5 Max, 18 cores, macOS 27.0.1.
    • Bun. 1.4.4 for both runs.
    • Script. apps/hocuspocus.server/scripts/bench-prisma-bytea.ts. It uses the real src/lib/prisma.ts client, so it uses the one PrismaPg pool. The measurement code did not change between runs.
    • Fixtures. The same in both runs, built from a fixed seed. A 5,357,733 B head, a 10,521,216 B version pair and a 680 B small document.
    • n. 7 samples per number, after one warm-up. Each cell shows the median, with min–max in brackets.
    • Memory rows. Bare mode reads the child process maxRSS, because macOS has no cgroup. The cgroup row ran in docker run --memory=1g on linux-arm64.
    Measure 6.19.3 7.10.1 Change
    (a) Cold-load head read, loop block, 5.36 MB head (ms) 165.13 (113.68–176.43) 2.87 (1.97–4.70) −98.3%
    (b) history.watch read, loop block, same head (ms) 162.61 (103.70–182.96) 2.51 (2.05–3.25) −98.5%
    (c) Digest pair fetch peak, child maxRSS (MiB) 1037.20 (1028.86–1063.16) 199.25 (191.05–204.31) −80.8%
    (c) Digest pair fetch peak, cgroup memory.peak, 1 GiB limit (MiB) 993.54 (972.49–1024.00) 206.16 (196.59–313.52) −79.2%
    (d) Small document load (ms) 1.03 (0.78–1.48) 0.28 (0.25–0.43) −72.8%
    (d) Small document save (ms) 5.65 (3.55–8.84) 2.50 (2.20–3.84) −55.8%
    • 6.19.3 hit the limit. memory.peak cannot read above memory.max. One 6.19.3 sample read exactly 1024 MiB, and the median is 97% of the limit. Read that row as "at the 1 GiB limit".
    • Both cgroup runs had 0 OOM kills.
    • What the bench does not prove. Memory sizes carry over to the amd64 host. The times need an amd64 run to confirm them.
    • bun audit, 2026-10-25. No advisory names deepmerge-ts or any @prisma/* package. @prisma/config 7.10.1 pulls deepmerge-ts 8.0.2, so the root [email protected] pin is dropped.
    • One new path reaches fast-uri 3.1.7, through the prisma CLI. That version was already in the lock through ESLint, Stylelint and webpack. The runtime client does not load it.

    Production read (2026-10-25, from #576). ENABLE_SCHEMA_MIGRATION is off. It is unset in both WS replicas, REST and the worker, and the code reads unset as false. So cold load does no second decode.

    Production deploy (run 41608014517, 2026-11-03).

    • The migrate step loaded prisma.config.ts and applied the two pending migrations.

    • REST, WS and the worker each came up with 2 of 2 replicas healthy.

    • Each service passed its internal health check.

    • The same run passed Backend Tests and Backend E2E, on real Postgres and Redis.

    Tree check (current main).

    • The acceptance git grep for Prisma 6.19 pins finds nothing.
    • The three package pins read 7.10.1.
    • Webapp and admin have no @prisma/client import.
    • No hand DocumentMetadata type is left in hocuspocus.
    • VersionTrigger has one source, apps/hocuspocus.server/src/types/versionTrigger.ts. The webapp type-imports it.
    • fetchDocument in the webapp still has no [key: string]: any.

    Behaviour items.

    • Persist. The Backend E2E job runs e2e-store-pipeline.ts on real Postgres. It waits for a new Documents row, so a persist still mints one.
    • Settings search and the slug P2002 cede. Their tests in tests/integration/documents.test.ts use a mock Prisma client. So they do not prove Prisma 7 behaviour against a real database.

    Can close now: yes, after one manual check of Settings search and a slug P2002 cede on the deployed build. The amd64 timings are not measured, and no item asks for them.

  10. HMarzban commented on Nov 9, 2026

    @HMarzban
    CollaboratorAuthor

    Maintainer ruling, 2026-11-09

    A local proof on real Postgres covers the slug P2002 cede. No production write is needed to force a slug collision.

    Local proof, 2026-11-09

    The maintainer ruled on 2026-11-09 that a local proof on real Postgres covers the slug P2002 cede. This comment is that proof. It also covers persist and Settings search locally.

    Setup. Local stack from make dev-local, on main at d31ed9033. Postgres is docsy-postgres-local. REST runs on :4000, and it loads the generated client with clientVersion 7.10.1. bunx prisma -v prints 7.10.1 for both prisma and @prisma/client. The signed-in user is Swarm Actor 1 from packages/document-swarm. Its session came from the swarm sign-in code. No credentials were typed.

    1. Persist mints a Documents row.

    • Headless Chromium opened localhost:3000/prisma-proof-1794201086330 and typed one line.
    • The first-edit anchor wrote the DocumentMetadata row MzKA4TqaI0SEAWSkeVY, owned by the actor.
    • One Documents row landed 10 s later: version 1, trigger websocket, 1028 B.

    2. Settings search returns matches.

    • The call matches the webapp: GET /api/documents?title=…&ownerId=<actor>&scope=all&sort=updatedAt_desc&limit=20&offset=0, with the actor token.
    • Query prisma proof 1794201086330 returned 200, total 1, and the new pad.
    • The service joins words as prisma & proof & 1794201086330. A contains filter cannot match that text, so only the Postgres full-text search filter matched. So fullTextSearchPostgres still works on Prisma 7.
    • Control: one word returned the pad. A query with a made-up word returned total 0.

    3. A slug P2002 cede returns.

    • Two POST /api/documents/MzKA4TqaI0SEAWSkeVY/duplicate calls went out together in one Promise.all.
    • Both returned 200. One got prisma-proof-1794201086330-copy. The other got prisma-proof-1794201086330-copy-1794201098842-bcz7l.
    • withUniqueSlug adds that suffix only after a slug P2002. Both rows are in DocumentMetadata.
    • A plain POST /api/documents on the taken slug returned 409 CONFLICT, with field: ["DocumentMetadata_slug_key"] and prismaCode: "P2002".
    • That field is the index name, not ["slug"]. So the Prisma 7 adapter reports constraint.index here, with no fields. The retry works only because withUniqueSlug also matches DocumentMetadata_slug_key. A mock client cannot show this.
    • Scope: this run used the duplicate path. The worker first save and MCP create_document call the same withUniqueSlug (src/lib/slug.ts). They were not run here.

    4. Tests and tree.

    • Local bun test in apps/hocuspocus.server: 1187 pass, 7 skip, 0 fail.
    • bunx prisma migrate status: 19 migrations found, schema up to date.
    • The local store-pipeline e2e was not run, because a second worker would compete on the live queue. Run 41608014517 printed store pipeline E2E: PASSED and versions E2E: PASSED.
    • The acceptance git grep for 6.19 pins finds nothing.

    5. bun audit (Bun 1.4.4, 2026-11-09).

    • It reports 26 advisories. None names deepmerge-ts or any @prisma/* package.
    • [email protected] comes in only through @prisma/[email protected]. The root has no deepmerge-ts pin, so the pin stays dropped.
    • The [email protected] advisory is a different package, from jest and next-pwa.

    Production. Run 41608014517 applied two migrations through prisma.config.ts. REST, WS and the worker each came up with 2 healthy replicas.

    Production Settings search, 2026-11-09. Read-only, in the maintainer's signed-in browser on docs.plus. Settings → Documents → Search documents:

    • "smoke" listed 3 matches. "mermaid" listed 1 match.
    • The search ran on the server: GET https://prodback.docs.plus/api/documents?…&title=mermaid returned 200.

    Status. Every box is met: this comment, the 2026-11-03 result comment, and deploy run 41608014517. Closing as completed.

  11. modified the milestones: v2.3.0, v2.3.6 on Nov 9, 2026
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

    DevOpsdependenciesenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions