Skip to content

Add native enum support to select field with db.type: 'enum'#348

Merged
borisno2 merged 1 commit intomainfrom
claude/add-enum-select-field-ZJScS
Mar 1, 2026
Merged

Add native enum support to select field with db.type: 'enum'#348
borisno2 merged 1 commit intomainfrom
claude/add-enum-select-field-ZJScS

Conversation

@borisno2
Copy link
Member

@borisno2 borisno2 commented Mar 1, 2026

Summary

This PR adds support for native database enums to the select field by introducing a new db.type: 'enum' option. When enabled, select fields generate Prisma enum blocks instead of storing values as plain strings, matching Keystone 6's enum select behavior.

Key Changes

  • Select field enum support: Added db.type: 'enum' option to the select field configuration that generates native Prisma enum types
  • Enum name derivation: Enum names are automatically derived from list and field names in PascalCase (e.g., PostStatus, UserRole)
  • Validation: Added validation to ensure enum values are valid Prisma identifiers (letters, digits, underscores; must start with a letter)
  • Prisma schema generation:
    • Generates enum blocks in the schema for fields with db.type: 'enum'
    • Uses unquoted default values for enum fields (@default(draft) not @default("draft"))
    • Supports @map modifier for database column mapping
  • Type system: Updated getPrismaType signature to accept optional listName parameter for enum name generation and return enumValues array
  • Backward compatibility: Default behavior (no db.type or db.type: 'string') preserves existing String column behavior
  • Comprehensive tests: Added 14 new test cases covering enum validation, schema generation, optional/required fields, multiple enums, and snapshot testing

Implementation Details

  • Enum value validation uses regex pattern /^[A-Za-z][A-Za-z0-9_]*$/ to enforce Prisma identifier rules
  • The getPrismaType method now returns an optional enumValues array that triggers enum block generation
  • Enum definitions are collected in a first pass through all fields before model generation
  • TypeScript union types are generated identically for both string and enum select fields
  • Zod schema validation works the same for both types, validating against the provided options

https://claude.ai/code/session_0148fU5k5gN6nr4mAtGpjUZD

Adds native Prisma enum storage for the select field, matching Keystone 6's
enum select behaviour. When db.type is 'enum', the Prisma generator emits an
enum block (e.g. PostStatus) and uses the enum type in the model instead of
String. Default values are unquoted per Prisma enum syntax.

- SelectField type gains db.type ('string'|'enum'), db.map, and defaultValue
- getPrismaType signature extended with optional listName and enumValues return
- select() builder validates enum values are valid Prisma identifiers
- Prisma generator collects enum definitions in a first pass and emits blocks
- Tests added: select field unit tests, schema validation tests, generator tests

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

vercel bot commented Mar 1, 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 1, 2026 10:28am

@changeset-bot
Copy link

changeset-bot bot commented Mar 1, 2026

🦋 Changeset detected

Latest commit: c0c95dd

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 Minor
@opensaas/stack-cli Minor
@opensaas/stack-auth Minor
@opensaas/stack-rag Minor
@opensaas/stack-storage Minor
@opensaas/stack-tiptap Minor
@opensaas/stack-ui Minor
@opensaas/stack-storage-s3 Minor
@opensaas/stack-storage-vercel Minor

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

@borisno2 borisno2 enabled auto-merge (squash) March 1, 2026 10:31
@borisno2 borisno2 merged commit 5410cb6 into main Mar 1, 2026
6 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 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 #966 for commit c0c95dd by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 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 #966 for commit c0c95dd by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2026

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

Status Category Percentage Covered / Total
🔵 Lines 75.53% 1161 / 1537
🔵 Statements 75.17% 1205 / 1603
🔵 Functions 79.59% 156 / 196
🔵 Branches 64.67% 531 / 821
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/cli/src/generator/prisma.ts 88.42% 81.87% 100% 88.75% 16, 26, 40-44, 55, 68, 75, 79, 100, 106, 112-114, 117, 142, 161-163, 178-184, 214, 229, 241, 451, 463, 498-499, 618
Generated in workflow #966 for commit c0c95dd by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 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 #966 for commit c0c95dd by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 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 #966 for commit c0c95dd by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 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 #966 for commit c0c95dd by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 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 #966 for commit c0c95dd by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 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 #966 for commit c0c95dd 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