Skip to content

Upgrade to Prisma 7 with database adapter support#132

Merged
borisno2 merged 5 commits intomainfrom
upgrade/prisma-7
Nov 21, 2025
Merged

Upgrade to Prisma 7 with database adapter support#132
borisno2 merged 5 commits intomainfrom
upgrade/prisma-7

Conversation

@borisno2
Copy link
Copy Markdown
Member

Summary

This PR upgrades OpenSaas Stack to Prisma 7, which requires database adapters for all database connections.

Breaking Changes

Required prismaClientConstructor

Prisma 7 no longer supports the url field in the datasource block. Instead, database connections must be configured via adapters passed to the PrismaClient constructor.

All configs must now include prismaClientConstructor:

import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3'
import Database from 'better-sqlite3'

export default config({
  db: {
    provider: 'sqlite',
    url: process.env.DATABASE_URL || 'file:./dev.db',
    prismaClientConstructor: (PrismaClient) => {
      const db = new Database(process.env.DATABASE_URL || './dev.db')
      const adapter = new PrismaBetterSQLite3(db)
      return new PrismaClient({ adapter })
    },
  },
})

Generated Schema Changes

  • Generator provider changed from prisma-client-js to prisma-client
  • Removed url field from datasource block
  • Database URL now passed via adapter in prismaClientConstructor

Changes Made

Core (@opensaas/stack-core)

  • ✅ Made prismaClientConstructor required in DatabaseConfig type
  • ✅ Updated JSDoc with comprehensive examples for SQLite, PostgreSQL, and Neon
  • ✅ Updated main CLAUDE.md documentation

CLI (@opensaas/stack-cli)

  • ✅ Updated schema generator to use prisma-client provider
  • ✅ Removed url generation from datasource block
  • ✅ Updated context generator to require prismaClientConstructor
  • ✅ Added helpful error message when adapter is missing
  • ✅ Updated CLI CLAUDE.md documentation

Examples (12 total)

  • ✅ Updated all SQLite examples with @prisma/adapter-better-sqlite3
  • ✅ Updated PostgreSQL example with @prisma/adapter-pg
  • ✅ Added adapter dependencies to all package.json files
  • ✅ Updated all opensaas.config.ts files with prismaClientConstructor
  • ✅ Regenerated all Prisma schemas

Templates (create-opensaas-app)

  • ✅ Updated basic template with SQLite adapter
  • ✅ Updated with-auth template with SQLite adapter

Tests

  • ✅ Fixed RAG plugin tests with mock adapter configs
  • ✅ Fixed CLI generator tests with required prismaClientConstructor
  • ✅ Updated 11 test snapshots
  • ✅ All tests passing (44/44 in CLI, all in core, storage, rag)

Migration Guide for Users

1. Install Prisma 7 and adapter

# For SQLite
pnpm add @prisma/client@7 @prisma/adapter-better-sqlite3 better-sqlite3
pnpm add -D prisma@7

# For PostgreSQL
pnpm add @prisma/client@7 @prisma/adapter-pg pg
pnpm add -D prisma@7

# For MySQL
pnpm add @prisma/client@7 @prisma/adapter-mysql mysql2
pnpm add -D prisma@7

2. Update opensaas.config.ts

Add prismaClientConstructor to your db config (see examples above in Breaking Changes section).

3. Regenerate schema and client

pnpm generate
npx prisma generate

4. Push schema to database

pnpm db:push

Testing

  • ✅ All unit tests passing
  • ✅ Example generation verified (blog example tested)
  • ✅ Generated schemas correct (no url, uses prisma-client)
  • ✅ Context generation correct (uses prismaClientConstructor)

References

🤖 Generated with Claude Code

## Changes

### Core
- Made `prismaClientConstructor` required in DatabaseConfig
- Updated type definitions with comprehensive adapter examples
- Added helpful error messages for missing adapter configuration

### CLI
- Updated Prisma schema generator to use `prisma-client` provider
- Removed `url` field from datasource block generation
- Updated context generator to require and use `prismaClientConstructor`
- Added error message with SQLite adapter example when constructor missing

### Examples (12 total)
- Added adapter dependencies to all example package.json files
- Updated all opensaas.config.ts files with `prismaClientConstructor`
- SQLite examples: Added @prisma/adapter-better-sqlite3 + better-sqlite3
- PostgreSQL example: Added @prisma/adapter-pg + pg
- Regenerated all Prisma schemas with new format

### Templates
- Updated create-opensaas-app templates with adapter configuration
- Both basic and with-auth templates now include required adapters

### Tests
- Fixed RAG plugin tests with mock adapter configs
- Fixed CLI generator tests with required prismaClientConstructor
- Updated 11 test snapshots to match new generated code
- All tests passing

### Documentation
- Updated CLAUDE.md with Prisma 7 requirements and examples
- Updated CLI CLAUDE.md with new schema format
- Added examples for SQLite, PostgreSQL, and Neon adapters

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Nov 21, 2025

🦋 Changeset detected

Latest commit: 5f838ab

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

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

@vercel
Copy link
Copy Markdown

vercel bot commented Nov 21, 2025

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

Project Deployment Preview Comments Updated (UTC)
stack-docs Ready Ready Preview Comment Nov 21, 2025 9:32pm

- Remove outdated Prisma schema datasource example from deployment.md
- Clarify prismaClientConstructor is required in config.md
- Update database adapter documentation
- Removed url from DatabaseConfig type definition
- Database connection URLs now passed directly to adapters
- Updated all 12 examples to pass url to adapters
- Updated 2 templates (basic, with-auth)
- Updated all test mocks to remove url field
- Updated config.md API reference documentation
- Updated changeset to document url removal

Breaking Change: The url field is no longer part of the db config object.
Connection URLs are now passed directly to database adapters in prismaClientConstructor.
- Add eslint-disable comments for test mock constructors
- Remove unused error variables in catch blocks
- Prefix unused variable with underscore
- Remove unused imports
- Fix syntax errors (missing commas)
@github-actions
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.08% 178 / 423
File CoverageNo changed files found.
Generated in workflow #449 for commit 5f838ab by the Vitest Coverage Report Action

@github-actions
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 #449 for commit 5f838ab by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

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

Status Category Percentage Covered / Total
🔵 Lines 75.65% 87 / 115
🔵 Statements 75% 90 / 120
🔵 Functions 76.92% 30 / 39
🔵 Branches 65.38% 68 / 104
File CoverageNo changed files found.
Generated in workflow #449 for commit 5f838ab by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

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

Status Category Percentage Covered / Total
🔵 Lines 65.16% 202 / 310
🔵 Statements 63.32% 202 / 319
🔵 Functions 66.66% 20 / 30
🔵 Branches 47.89% 57 / 119
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/cli/src/generator/context.ts 90% 50% 100% 90% 208
packages/cli/src/generator/prisma.ts 92.18% 80.76% 100% 93.65% 11, 21, 45, 54, 102
packages/cli/src/generator/types.ts 84.55% 62.5% 83.33% 88.46% 11, 21, 30, 40, 65, 99, 133, 161, 207-222, 230-234, 261-263
Generated in workflow #449 for commit 5f838ab by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

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

Status Category Percentage Covered / Total
🔵 Lines 84.3% 419 / 497
🔵 Statements 83.39% 427 / 512
🔵 Functions 95.83% 69 / 72
🔵 Branches 74.63% 306 / 410
File CoverageNo changed files found.
Generated in workflow #449 for commit 5f838ab by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

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

Status Category Percentage Covered / Total
🔵 Lines 43.45% 73 / 168
🔵 Statements 43.78% 74 / 169
🔵 Functions 45.45% 15 / 33
🔵 Branches 40.13% 61 / 152
File CoverageNo changed files found.
Generated in workflow #449 for commit 5f838ab by the Vitest Coverage Report Action

@github-actions
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 #449 for commit 5f838ab by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

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 #449 for commit 5f838ab by the Vitest Coverage Report Action

@borisno2 borisno2 merged commit fcf5cb8 into main Nov 21, 2025
12 checks passed
@borisno2 borisno2 deleted the upgrade/prisma-7 branch November 21, 2025 21:38
@github-actions github-actions bot mentioned this pull request Nov 23, 2025
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.

1 participant