Skip to content

docs: canonical Keystone → stack migration guide (#490)#522

Merged
borisno2 merged 2 commits into
mainfrom
claude/issue-490-canonical-migration-guide
Jun 4, 2026
Merged

docs: canonical Keystone → stack migration guide (#490)#522
borisno2 merged 2 commits into
mainfrom
claude/issue-490-canonical-migration-guide

Conversation

@borisno2

@borisno2 borisno2 commented Jun 4, 2026

Copy link
Copy Markdown
Member

Implements #490
Part of #486

HITL — holds for human review/approval before merge

This is the public face of migration and spans every area, so per #490 it is human-in-the-loop: an agent drafted it, but the EM reviews and approves before merge. Do not merge without human approval.

What changed (docs-only)

Promotes a single canonical, published Keystone → stack migration guide as the source of truth, folding in the specs/keystone-migration.md recipes and reflecting the shipped Area A–E behaviour.

Source of truth & link-only sections

API verification

Every config/API snippet was cross-checked against shipped code on main:

  • Field/db options vs packages/core/src/config/types.ts and packages/core/src/fields/index.ts (db.keystoneCompat, db.timestamps global + per-list, select db.type/db.enumName/db.isNullable, db.schemas/db.schema/db.map, OutputConfig).
  • Query API vs packages/core/src/query/index.ts (defineFragment, runQuery/runQueryOne, ResultOf, RelationSelector).
  • Auth adoptBetterAuthTables() vs packages/auth and the auth guide's adoption section.
  • Image multi-column db.columns: 'keystone' vs specs/keystone-image-migration.md + ADR-0006.
  • migrate-context-calls recipe summaries vs the skill's SKILL.md.
  • Output paths vs packages/cli/src/generator/output-paths.ts.

Checks

  • pnpm install --prefer-offline — clean
  • docs link-check (pnpm --filter opensaas-stack-docs link-check) — pass (5 required pages resolve, internal links in 4 migration docs valid)
  • docs build (next build, runs link-check prebuild) — pass (all pages generated, incl. /docs/guides/migrating-from-keystone)
  • pnpm lintpass (0 errors; only pre-existing warnings in untouched files)
  • pnpm format:checkpass

No changeset/plugin-version bump: docs-only, no packages/* or claude-plugins/* changes.

For the reviewer to focus on

  • Source-of-truth call: I extended the existing migrating-from-keystone.md as canonical (rather than restructuring around migration.md) because the CLI and link-check already treat it as canonical. Confirm that's the intended page.
  • migration.md trimming: I kept the ## Migrating context.graphql.run heading (now a short pointer) so core-concepts/queries.md's existing #migrating-contextgraphqlrun anchor link still resolves to a real section. Confirm you're happy keeping that anchor vs removing the section entirely.
  • External links to specs/ and docs/adr/: these point to GitHub blob/main/... URLs (they aren't docs-site pages, so the link-check doesn't verify them). Worth a sanity check that those paths are the intended targets.
  • bigInt() mapping: there is no dedicated bigInt() builder, so I documented integer({ db: { nativeType: 'BigInt' } }) as the mapping — please confirm that's the recommended approach.

https://claude.ai/code/session_01ULd2HCT8dUve9aa9gKi6sX


Generated by Claude Code

Expand guides/migrating-from-keystone.md into the comprehensive, single
source of truth for Keystone -> stack migration, folding in the
specs/keystone-migration.md recipes and reflecting shipped Area A-E
behaviour:

- Field-type, hook (pipeline timing), and access mapping tables.
- Generator parity (Area A): keystoneCompat empty-string text defaults,
  timestamps off by default + db.timestamps opt-in, bare singleton id,
  select db.isNullable/db.enumName, honoured defaultValue.
- context.graphql.run -> context.db.* summarised; links the hardened
  migrate-context-calls skill recipes (#488) rather than duplicating.
- Image/file (Area C): links the non-destructive multi-column recipe (#479).
- Auth adoption (Area D): links the adoptBetterAuthTables() recipe (#483).
- Configurable output paths (Area E, #485) for side-by-side coexistence.
- Multi-schema preservation + admin-UI parity notes.

Reduce specs/keystone-migration.md to a design-notes pointer at the
published guide. Trim the duplicated context.graphql.run section and
Keystone field table in guides/migration.md to point at the canonical
guide (no stale duplicates). Make the canonical guide the first migration
entry in the docs nav.

Docs-only change; link-check, docs build, lint, and format:check pass.

https://claude.ai/code/session_01ULd2HCT8dUve9aa9gKi6sX
@changeset-bot

changeset-bot Bot commented Jun 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2808ee8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel

vercel Bot commented Jun 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
stack-docs Ready Ready Preview, Comment Jun 4, 2026 5:52am

@borisno2 borisno2 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — canonical Keystone → stack migration guide (#490)

Verdict: REQUEST CHANGES (posted as a Comment review because GitHub blocks a formal Approve/Request-changes when the reviewing identity authored the PR). One factual defect (the bigInt() mapping) should be fixed before merge; everything else is accurate and the consolidation is sound.

I cross-checked every config/API snippet against the shipped code on main (commit c97fb46). The vast majority verified clean. Findings below, ordered by severity.


🔴 Must fix

1. bigInt()integer({ db: { nativeType: 'BigInt' } }) is incorrect (field-type table §2).
This is the author's open question #4, and the answer is: no, this is not the recommended mapping and as written it produces an invalid schema.

  • integer().getPrismaType() (packages/core/src/fields/index.ts:192-225) returns Prisma scalar type Int and, when db.nativeType is set, appends @db.<nativeType> → so this emits someField Int? @db.BigInt.
  • @db.BigInt is not a valid native-type attribute for the Prisma Int scalar. Prisma models BigInt as a scalar type (BigInt, which maps to JS bigint), not as a @db. annotation on Int. Int @db.BigInt will fail prisma validate / generate (P1012) on Postgres/MySQL/SQLite.
  • Even if it generated, integer().getTypeScriptType() always returns type: 'number' (line 230), so you'd silently lose bigint precision in TS.
  • The stack's own migration tooling does not treat this as the BigInt path: packages/cli/src/migration/introspectors/prisma-introspector.ts:203 maps Prisma BigInttext() with the comment // No native support, and migration-generator.ts:527 special-cases BigInt/Decimal/Bytes. There is no bigInt() builder.

Recommendation: don't present integer({ db: { nativeType: 'BigInt' } }) as the mapping. Either (a) state that there is no native BigInt field and the tool maps it to text() (matching the introspector), and/or (b) recommend db.extendPrismaSchema to emit a real BigInt scalar column if the live DB has one. As written it will mislead migrators into an un-generatable schema.


🟡 Worth addressing

2. float()decimal() mapping changes the column type (field-type table §2).
Keystone's float() is a Float (double) column; decimal() emits Decimal @db.Decimal(p,s) (fields/index.ts:342-378). Mapping float → decimal is a destructive column-type change, which cuts against the guide's central "Schema parity / no destructive changes" promise. There is no float() builder in the stack, so some workaround is unavoidable — but the table should flag that Float → Decimal is a type change (consider decimal or extendPrismaSchema/nativeType to keep a real float), not present it as a clean same-shape mapping like the rows above it.


🟢 Verified accurate (no change needed)

Spot-checked and confirmed against source:

  • Generator parity (Area A): db.keystoneCompat (empty-string non-null text default, opt-in, explicit defaultValue wins, nullable/non-text untouched) — config/types.ts:1582, fields/index.ts:120-129. db.timestamps global + per-list override + P1012 dedupe — types.ts:1369,1554. Bare singleton id Int @id — matches. select db.type/db.enumName (default <List><Field>)/db.isNullable semantics and the → status AccountNoteStatusType? @default(open) example output — types.ts:643-700, fields/index.ts:854-915. Honoured defaultValue@default(...) on text/integer/json/checkbox/decimal/timestamp — confirmed.
  • Query API (Area B): defineFragment / runQuery / runQueryOne / ResultOf / RelationSelector all exist with the documented signatures and the nested { query, where, orderBy, take, skip } shape (query/index.ts), and are exported from the root @opensaas/stack-core (src/index.ts) — so the guide's import { defineFragment, type ResultOf } from '@opensaas/stack-core' is correct.
  • Output paths (Area E): OutputConfig.prismaSchema (default prisma/schema.prisma) and opensaasDir (default .opensaas) match types.ts:2087; exported from root.
  • Auth (Area D) & image/file (Area C): correctly linked, not duplicated. adoptBetterAuthTables() exists (packages/auth/src/config/adopt-better-auth-tables.ts). Image/file use @opensaas/stack-storage/fields with db.columns: 'keystone' (storage/src/fields/index.ts). The "7 image columns / 3 file columns" claim and the avatar_url/resume_filename… example names match IMAGE_COLUMN_PARTS / FILE_COLUMN_PARTS exactly (storage/src/utils/multi-column.ts).
  • Mapping tables: Access §4 — item is provided to operation access on update/delete (access/types.ts:270,304), so the access.item.* row is right. Hook §7 — the read pipeline (3 steps: DB → field access control → field resolveOutput) is correct; reads do not run afterOperation (context/index.ts findUnique/findMany only filter fields + resolveOutput). Note this means the repo's root CLAUDE.md read-order list (which adds a 4th "field afterOperation" step) is the stale one — the guide is right.
  • Consolidation soundness: single canonical page; migration.md trimmed to pointers while preserving the ## Migrating context.graphql.run heading (line 877), so core-concepts/queries.md's two #migrating-contextgraphqlrun anchors (lines 14, 178) still resolve. specs/keystone-migration.md reduced to a pointer + topic map; nav updated.
  • Tooling: CLI MIGRATION_GUIDE_URL === https://stack.opensaas.au/docs/guides/migrating-from-keystone (commands/migrate.ts:23, asserted in tests), --with-ai/--type keystone are valid flags, and /plugin install opensaas-migration@opensaas-stack-marketplace matches the marketplace (.claude-plugin/marketplace.json). The migrate-context-calls Recipe 1–4 summaries (where-shape, connect/disconnect/set: [], "never write scalar FK — silently stripped", gql.tada/VariablesOf→factory, fragment→include + null-on-access-denied) all faithfully match the skill's SKILL.md.
  • Links: all four ADR blob/main URLs (0004–0007) and both specs/*.md targets exist on disk.

Recommendations on the four flagged open questions

  1. Is migrating-from-keystone.md the right canonical page?Yes. The CLI's MIGRATION_GUIDE_URL already points at exactly this page (and a test locks the value), so extending it rather than restructuring around migration.md is the correct call.
  2. Keep vs delete the ## Migrating context.graphql.run pointer section in migration.md?Keep it. core-concepts/queries.md links into #migrating-contextgraphqlrun in two places; the heading must survive or those anchors 404. Leaving it as a short pointer is the right move.
  3. GitHub blob/main URLs to specs/ and docs/adr/.Fine to keep. All targets exist and these aren't docs-site pages, so blob URLs are appropriate (link-check correctly doesn't validate them). Minor optional nit: blob/main URLs aren't version-pinned, so they can drift if a file is renamed — acceptable for design-notes/ADR references.
  4. bigInt() mapping.Not correct as written (see 🔴 #1). Needs revision before this ships as the public source of truth.

Summary: Strong, accurate, well-consolidated guide — the Area A–E technical content, query API, links, and tooling references all check out against shipped code. The single blocking item is the bigInt() field mapping (#1), which would lead a migrator to a schema Prisma rejects; the float()→decimal() row (#2) should also be caveated. Fix those two and this is good to merge. Holding for human approval per the HITL note.

https://claude.ai/code/session_01ULd2HCT8dUve9aa9gKi6sX


Generated by Claude Code

…#490)

The migration guide's field-type table documented Keystone bigInt() →
integer({ db: { nativeType: 'BigInt' } }), which is invalid: it emits
Int @db.BigInt, a combination Prisma rejects (@db.BigInt is not a valid
native type for the Int scalar), and the TS type stays number anyway.

Rewrite the bigInt row to match what the stack actually does. The
migration introspector
(packages/cli/src/migration/introspectors/prisma-introspector.ts:203)
maps Prisma BigInt → text() with a "No native support" comment and warns
the field is mapped to text(); there is no bigInt() builder. Document
that honestly, including the string-storage precision caveat.

Also caveat the float() → decimal() row: there is no float() builder and
decimal() is a type change (Float → Decimal, number → decimal.js
Decimal), not byte-for-byte parity — call out the precision/behaviour
difference instead of presenting a clean 1:1 mapping.

Ran prettier --write on both touched docs to satisfy format:check.

https://claude.ai/code/session_01ULd2HCT8dUve9aa9gKi6sX

borisno2 commented Jun 4, 2026

Copy link
Copy Markdown
Member Author

Follow-up accuracy fix pushed to claude/issue-490-canonical-migration-guide (2808ee8) — field-type mapping table only, no restructuring, still HITL/no merge.

bigInt() correction (was wrong). The previous row documented bigInt()integer({ db: { nativeType: 'BigInt' } }). That's invalid: per packages/core/src/fields/index.ts (the db.nativeType branch around L204-207, locked by the test at packages/core/tests/field-types.test.ts:299-303) it emits Int @db.BigInt, a combination Prisma rejects — @db.BigInt is not a valid native-type attribute for the Int scalar — and the TS type stays number regardless.

I grounded the corrected mapping in the migration introspector: packages/cli/src/migration/introspectors/prisma-introspector.ts:203 maps Prisma BigInttext() with a // No native support comment, and getWarnings() (L220-223, mirrored in migration-generator.ts:527-530) emits uses unsupported type "BigInt" - will be mapped to text(). There is no bigInt() builder anywhere in packages/. The row now reads bigInt()text(), states there is no native BigInt field, notes values are stored/returned as strings (exact preservation for IDs but no numeric operators), and explicitly warns against the invalid integer({ db: { nativeType: 'BigInt' } }) snippet.

float() caveat. There is no float() builder, and decimal() (packages/core/src/fields/index.ts:280) emits Decimal @db.Decimal(precision, scale) (defaults 18, 4) with a decimal.js Decimal runtime type. The row now flags float()decimal() as a type change, not 1:1 parity (column FloatDecimal, runtime numberDecimal), and tells you to size precision/scale for your existing values and review rounding/precision differences.

This also supersedes the open "please confirm that's the recommended approach" question in the PR description for bigInt() — the answer is no, and the row is fixed accordingly.

Checks (re-run on this branch after the change):

  • pnpm install --prefer-offline — clean
  • docs link-check (pnpm --filter opensaas-stack-docs link-check) — pass (5 required pages, internal links in 4 migration docs valid)
  • pnpm build (incl. docs next build + link-check prebuild) — pass (11/11 tasks, all 34 docs pages generated)
  • pnpm lint — pass (0 errors; only pre-existing warnings in untouched files)
  • pnpm format:check — pass

Note: format:check was actually failing on the prior PR head (3a01cfb) for both docs/content/guides/migrating-from-keystone.md and specs/keystone-migration.md (misaligned markdown tables). I ran prettier --write on both, which is why the diff includes whitespace-only table-alignment churn beyond the two row edits — no other content changed. Docs-only, no changeset/plugin-version bump needed.

https://claude.ai/code/session_01ULd2HCT8dUve9aa9gKi6sX


Generated by Claude Code

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for Core Package Coverage (./packages/core)

Status Category Percentage Covered / Total
🔵 Lines 89.64% (🎯 65%) 580 / 647
🔵 Statements 88.85% (🎯 65%) 590 / 664
🔵 Functions 98.09% (🎯 62%) 103 / 105
🔵 Branches 77.17% (🎯 50%) 382 / 495
File CoverageNo changed files found.
Generated in workflow #1129 for commit 2808ee8 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for UI Package Coverage (./packages/ui)

Status Category Percentage Covered / Total
🔵 Lines 76.03% 92 / 121
🔵 Statements 75.39% 95 / 126
🔵 Functions 75.6% 31 / 41
🔵 Branches 65.78% 75 / 114
File CoverageNo changed files found.
Generated in workflow #1129 for commit 2808ee8 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for CLI Package Coverage (./packages/cli)

Status Category Percentage Covered / Total
🔵 Lines 72.88% 1250 / 1715
🔵 Statements 72.67% 1295 / 1782
🔵 Functions 81.13% 172 / 212
🔵 Branches 61.04% 536 / 878
File CoverageNo changed files found.
Generated in workflow #1129 for commit 2808ee8 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for Auth Package Coverage (./packages/auth)

Status Category Percentage Covered / Total
🔵 Lines 74.64% 159 / 213
🔵 Statements 69.74% 166 / 238
🔵 Functions 83.11% 64 / 77
🔵 Branches 70.67% 94 / 133
File CoverageNo changed files found.
Generated in workflow #1129 for commit 2808ee8 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for Storage Package Coverage (./packages/storage)

Status Category Percentage Covered / Total
🔵 Lines 69.67% 170 / 244
🔵 Statements 71.59% 189 / 264
🔵 Functions 80.28% 57 / 71
🔵 Branches 68.29% 168 / 246
File CoverageNo changed files found.
Generated in workflow #1129 for commit 2808ee8 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for RAG Package Coverage (./packages/rag)

Status Category Percentage Covered / Total
🔵 Lines 47.97% 355 / 740
🔵 Statements 48.14% 377 / 783
🔵 Functions 54.26% 70 / 129
🔵 Branches 42.55% 180 / 423
File CoverageNo changed files found.
Generated in workflow #1129 for commit 2808ee8 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for Storage S3 Package Coverage (./packages/storage-s3)

Status Category Percentage Covered / Total
🔵 Lines 100% 40 / 40
🔵 Statements 100% 40 / 40
🔵 Functions 100% 9 / 9
🔵 Branches 100% 19 / 19
File CoverageNo changed files found.
Generated in workflow #1129 for commit 2808ee8 by the Vitest Coverage Report Action

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for Storage Vercel Package Coverage (./packages/storage-vercel)

Status Category Percentage Covered / Total
🔵 Lines 100% 38 / 38
🔵 Statements 100% 38 / 38
🔵 Functions 100% 8 / 8
🔵 Branches 100% 22 / 22
File CoverageNo changed files found.
Generated in workflow #1129 for commit 2808ee8 by the Vitest Coverage Report Action

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.

2 participants