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 postgresqlThis will:
- Prompt for driver (MySQL, PostgreSQL, SQLite, MongoDB), or use
--yes(default sqlite) - Write
.env(DATABASE_DRIVER,DATABASE_URL) - Write
prisma/schema.prismawith Better Auth models andurl = env("DATABASE_URL") - Write
lib/prisma.ts(export default prisma) - Write
prisma/seed.tsstub andpackage.jsonprisma.seed - Install
@prisma/client@6.18.0andprisma@6.18.0unless skipped - Run
prisma generate
Then:
# edit prisma/schema.prisma — add your models
shadpanel db migrate make add_posts
shadpanel db migrate run
shadpanel resource PostPrisma 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 prismaGenerated 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 statusmake 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 templateUse 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 dataIntrospection
shadpanel db pull
shadpanel db generateConnection 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.prismaonly; keepDATABASE_URLin.env - Prefer
migrate make/runoverpushonce you share a database - Import
prismafrom@/lib/prisma(singleton) instead ofnew PrismaClient()in every file - Back up before
db reset
Troubleshooting
- Cannot connect — check the database is running and
DATABASE_URLin.env - Prisma not initialized on
resource— runshadpanel db initfirst - Schema drift —
db migrate status, thenmake/run, ordb pullfor an existing database