Skip to content

Fix singleton lists to use Int @id @default(1) matching Keystone 6#352

Merged
borisno2 merged 2 commits intomainfrom
claude/fix-singleton-id-schema-HOn4R
Mar 3, 2026
Merged

Fix singleton lists to use Int @id @default(1) matching Keystone 6#352
borisno2 merged 2 commits intomainfrom
claude/fix-singleton-id-schema-HOn4R

Conversation

@borisno2
Copy link
Member

@borisno2 borisno2 commented Mar 3, 2026

fixes #350

Summary

This PR fixes singleton lists to generate Int @id @default(1) in the Prisma schema instead of String @id @default(cuid()), matching Keystone 6's behavior for singleton records.

Key Changes

  • Prisma schema generation: Updated generatePrismaSchema() to conditionally generate Int @id @default(1) for singleton lists and String @id @default(cuid()) for regular lists
  • TypeScript type generation: Modified generateModelOutputType() to generate id: number for singleton lists and id: string for regular lists
  • Create operation: Updated the create handler to automatically set id: 1 when creating singleton records
  • Test coverage: Added comprehensive tests for both singleton and regular model ID generation
  • Test updates: Updated all singleton test mocks to use integer IDs instead of string IDs
  • Example schema: Updated the blog example's Settings model to use the new singleton ID format
  • Migration guide: Added changeset documentation with SQL migration examples for existing databases

Implementation Details

  • Singleton lists now enforce id: 1 at the database level via Prisma's @default(1) constraint
  • The create operation automatically includes id: 1 in the data payload for singleton lists
  • This change ensures data consistency and simplifies migration from Keystone 6 without data loss
  • Existing databases with string IDs will require manual SQL migrations (documented in changeset)

https://claude.ai/code/session_01Keyrjjdhy3ypkZNzeg34re

…haviour

Singleton lists (isSingleton: true) previously generated String @id @default(cuid())
in the Prisma schema, which differed from Keystone 6's Int @id with a value always
set to 1. This caused data loss issues when migrating from Keystone 6 as the integer
primary key could not be automatically converted to text.

Changes:
- Prisma schema generator now emits `Int @id @default(1)` for singleton lists
- Context create function injects `id: 1` into singleton record creation data
- Types generator uses `id: number` in Output type for singleton lists
- Blog example schema updated to reflect new singleton ID type
- Tests updated to use numeric ID (1) for singleton records
- Added explicit tests for singleton schema generation

Fixes #350

https://claude.ai/code/session_01Keyrjjdhy3ypkZNzeg34re
@vercel
Copy link

vercel bot commented Mar 3, 2026

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

Project Deployment Actions Updated (UTC)
stack-docs Ready Ready Preview, Comment Mar 3, 2026 9:49am

@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2026

🦋 Changeset detected

Latest commit: b25b71a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@opensaas/stack-core Patch
@opensaas/stack-cli Patch
@opensaas/stack-auth Patch
@opensaas/stack-rag Patch
@opensaas/stack-storage Patch
@opensaas/stack-tiptap Patch
@opensaas/stack-ui Patch
@opensaas/stack-storage-s3 Patch
@opensaas/stack-storage-vercel Patch

Not sure what this means? Click here to learn what changesets are.

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

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

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

Status Category Percentage Covered / Total
🔵 Lines 86.17% 455 / 528
🔵 Statements 85.45% 464 / 543
🔵 Functions 97.22% 70 / 72
🔵 Branches 73.86% 325 / 440
File CoverageNo changed files found.
Generated in workflow #968 for commit b25b71a by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

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 #968 for commit b25b71a by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

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

Status Category Percentage Covered / Total
🔵 Lines 75.56% 1163 / 1539
🔵 Statements 75.2% 1207 / 1605
🔵 Functions 79.59% 156 / 196
🔵 Branches 64.72% 534 / 825
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/cli/src/generator/prisma.ts 88.52% 82.09% 100% 88.84% 16, 26, 40-44, 55, 68, 75, 79, 100, 106, 112-114, 117, 142, 161-163, 178-184, 214, 229, 241, 455, 467, 502-503, 622
packages/cli/src/generator/types.ts 93.34% 78.98% 93.33% 94.39% 11, 21, 30, 40, 68, 103-106, 151, 198, 238, 255, 356-360, 425-429, 464, 517, 868, 932-947, 955-959, 986-988
Generated in workflow #968 for commit b25b71a by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

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

Status Category Percentage Covered / Total
🔵 Lines 64.49% 89 / 138
🔵 Statements 61.03% 94 / 154
🔵 Functions 74.46% 35 / 47
🔵 Branches 62.79% 54 / 86
File CoverageNo changed files found.
Generated in workflow #968 for commit b25b71a by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

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

Status Category Percentage Covered / Total
🔵 Lines 42.44% 73 / 172
🔵 Statements 42.77% 74 / 173
🔵 Functions 42.85% 15 / 35
🔵 Branches 40.13% 61 / 152
File CoverageNo changed files found.
Generated in workflow #968 for commit b25b71a by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

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 #968 for commit b25b71a by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

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 #968 for commit b25b71a by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

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 #968 for commit b25b71a by the Vitest Coverage Report Action

@borisno2 borisno2 merged commit bd41b1e into main Mar 3, 2026
6 checks passed
@github-actions github-actions bot mentioned this pull request Mar 3, 2026
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.

Breaking migration: isSingleton models change primary key from Int (1) to String (cuid)

2 participants