Skip to Content
FeaturesDatabase Integration

Database Integration

Prisma 6.18.0 via shadpanel db. Templates live in the CLI package only — your app gets prisma/schema.prisma, never schema.prisma.template.

Quick Start

cd my-app shadpanel db init # or: shadpanel db init --yes --driver postgresql

This will:

  1. Prompt for driver (MySQL, PostgreSQL, SQLite, MongoDB), or use --yes (default sqlite)
  2. Write .env (DATABASE_DRIVER, DATABASE_URL)
  3. Write prisma/schema.prisma with Better Auth models and url = env("DATABASE_URL")
  4. Write lib/prisma.ts (export default prisma)
  5. Write prisma/seed.ts stub and package.json prisma.seed
  6. Install @prisma/client@6.18.0 and prisma@6.18.0 unless skipped
  7. Run prisma generate

Then:

# edit prisma/schema.prisma — add your models shadpanel db migrate make add_posts shadpanel db migrate run shadpanel resource Post

Prisma Client Singleton

db init and resource emit:

import { PrismaClient } from "@prisma/client" const globalForPrisma = globalThis as unknown as { prisma?: PrismaClient } export const prisma = globalForPrisma.prisma ?? new PrismaClient() if (process.env.NODE_ENV !== "production") { globalForPrisma.prisma = prisma } export default prisma

Generated resources use the default export:

import prisma from '@/lib/prisma'

Schema

Always:

datasource db { provider = "postgresql" // or mysql | sqlite | mongodb url = env("DATABASE_URL") } generator client { provider = "prisma-client-js" }

db init also appends Better Auth User, Session, Account, and Verification models. See Authentication.

Do not put credentials in the schema. db generate does not rewrite schema.prisma.

A leftover prisma/schema.prisma.template from older ShadPanel versions is obsolete.

Migrations

shadpanel db migrate make add_users shadpanel db migrate run shadpanel db migrate status

make diffs the database against the datamodel and writes SQL under prisma/migrations/. run is prisma migrate deploy plus client generate.

There is no shadpanel db migrate add_users --regenerate and no migrate update.

Push (prototyping)

shadpanel db push shadpanel db push --regenerate --force # overwrite schema from the CLI Prisma 6 template

Use migrations in production and in teams.

CRUD

import prisma from '@/lib/prisma' const user = await prisma.user.create({ data: { id: '…', name: 'Jane', email: 'jane@example.com', emailVerified: false }, }) const posts = await prisma.post.findMany({ include: { author: true }, take: 100, }) await prisma.post.update({ where: { id: 1 }, data: { published: true }, }) await prisma.post.delete({ where: { id: 1 } })

Server actions generated by shadpanel resource already wrap this pattern and call revalidatePath.

Server Components

import prisma from '@/lib/prisma' export default async function PostsPage() { const posts = await prisma.post.findMany({ orderBy: { createdAt: 'desc' } }) return <ul>{posts.map((p) => <li key={p.id}>{p.title}</li>)}</ul> }

Studio, Seed, Reset

shadpanel db studio shadpanel db seed # edit prisma/seed.ts first — the stub has no sample users shadpanel db reset # deletes all data

Introspection

shadpanel db pull shadpanel db generate

Connection Strings

DATABASE_DRIVER=postgresql DATABASE_URL="postgresql://user:password@localhost:5432/mydb?schema=public"

SQLite (--yes default): DATABASE_URL="file:./dev.db".

Better Auth’s adapter reads DATABASE_DRIVER (postgresql | mysql | sqlite).

Prisma 5 Detection

If package.json or the schema still looks like Prisma 5, the CLI warns and still emits Prisma 6. It never emits Prisma 5.

Best Practices

  • Edit schema.prisma only; keep DATABASE_URL in .env
  • Prefer migrate make / run over push once you share a database
  • Import prisma from @/lib/prisma (singleton) instead of new PrismaClient() in every file
  • Back up before db reset

Troubleshooting

  • Cannot connect — check the database is running and DATABASE_URL in .env
  • Prisma not initialized on resource — run shadpanel db init first
  • Schema drift — db migrate status, then make / run, or db pull for an existing database

Next Steps

Last updated on