Skip to content

Add db.isNullable and db.nativeType support to all field types#353

Merged
borisno2 merged 3 commits intomainfrom
claude/restore-db-field-config-9yUb1
Mar 3, 2026
Merged

Add db.isNullable and db.nativeType support to all field types#353
borisno2 merged 3 commits intomainfrom
claude/restore-db-field-config-9yUb1

Conversation

@borisno2
Copy link
Member

@borisno2 borisno2 commented Mar 3, 2026

Fixes #351

Summary

This PR extends database configuration options to all field types by moving db.isNullable and db.nativeType from field-specific definitions to the shared BaseFieldConfig. This allows consistent control over database-level nullability and native column types across all field types.

Key Changes

  • Unified DB configuration: Moved isNullable and nativeType from TextField to BaseFieldConfig, making them available on all field types (text, integer, password, json, timestamp, checkbox, decimal, calendarDay)

  • Nullability logic refactored: Updated getPrismaType() implementations across all field types to:

    • Use explicit db.isNullable when provided
    • Fall back to inferring from validation.isRequired when not specified
    • Properly handle edge cases (e.g., timestamp with @default(now()) is non-nullable by default)
  • Native type support: Added @db.<nativeType> attribute generation to field types that previously lacked it (integer, password, json, timestamp, checkbox)

  • Modifier string handling: Fixed modifier string generation across all field types by:

    • Using .trimStart() to clean up leading whitespace before returning
    • Ensuring consistent spacing between multiple modifiers (e.g., ? @db.Text)
    • Returning undefined instead of empty strings for fields with no modifiers
  • Comprehensive test coverage: Added 30+ new test cases covering:

    • db.isNullable: true/false behavior on all field types
    • Interaction between isNullable and validation.isRequired
    • db.nativeType generation with various field configurations
    • Combinations of nullable, default values, and native types

Implementation Details

The nullability logic now follows this precedence:

  1. If db.isNullable is explicitly set, use that value
  2. Otherwise, infer from validation.isRequired (required = non-nullable, optional = nullable)
  3. Special case: timestamp fields with @default(now()) are non-nullable by default

This allows developers to:

  • Make fields non-nullable at the DB level without API validation requirements
  • Explicitly mark fields as nullable regardless of validation settings
  • Override native database column types for database-specific optimizations

https://claude.ai/code/session_01LwV5V9az64n5xQr6gVKtuZ

Restores Keystone 6 db field-level config options that were missing from
OpenSaaS Stack, allowing independent control of DB-level nullability and
native database type overrides across all field types.

- Add isNullable and nativeType to BaseFieldConfig.db (inherited by all fields)
- Update integer(), password(), json(), timestamp(), checkbox() to handle
  db.isNullable (overrides validation.isRequired for DB nullability)
- Update integer(), password(), json(), timestamp() to handle db.nativeType
  (generates @db.<type> attribute in Prisma schema)
- text() already had support; simplify TextField.db (options now inherited)
- Simplify DecimalField.db and CalendarDayField.db (isNullable now inherited)
- Apply trimStart() consistently in getPrismaType returns for clean modifiers
- Add comprehensive tests covering all new db config combinations

Fixes #351

https://claude.ai/code/session_01LwV5V9az64n5xQr6gVKtuZ
@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 10:00am

@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2026

🦋 Changeset detected

Latest commit: 87158dc

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-auth Minor
@opensaas/stack-cli 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

After adding trimStart() to getPrismaType() in the core package, the CLI's
Prisma schema generator was concatenating type and modifiers without proper
spacing. The '?' nullability marker must attach directly to the type while
other modifiers (@Map, @default, @db.*) need a space separator.

https://claude.ai/code/session_01LwV5V9az64n5xQr6gVKtuZ
@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 #971 for commit 87158dc 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 #971 for commit 87158dc 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.61% 1166 / 1542
🔵 Statements 75.24% 1210 / 1608
🔵 Functions 79.59% 156 / 196
🔵 Branches 64.98% 540 / 831
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/cli/src/generator/prisma.ts 88.66% 82.73% 100% 88.97% 16, 26, 40-44, 55, 68, 75, 79, 100, 106, 112-114, 117, 142, 161-163, 178-184, 214, 229, 241, 455, 467, 505-506, 625
Generated in workflow #971 for commit 87158dc 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 #971 for commit 87158dc 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 #971 for commit 87158dc 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 #971 for commit 87158dc 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 #971 for commit 87158dc 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 #971 for commit 87158dc by the Vitest Coverage Report Action

@borisno2 borisno2 merged commit 28f2834 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.

Migration gap: db.isNullable and db.nativeType field options removed with no equivalent in OpenSaaS Stack

2 participants