This skill should be used when managing database schema, migrations, and seed data using Prisma ORM with Supabase PostgreSQL. Apply when setting up Prisma with Supabase, creating migrations, seeding data, configuring shadow database for migration preview, adding schema validation to CI, or managing database changes across environments.
Manage database schema, migrations, and seed data using Prisma ORM with Supabase PostgreSQL. Use when setting up Prisma with Supabase, creating migrations, seeding data, configuring shadow databases, or adding schema validation to CI workflows.
/plugin marketplace add hopeoverture/worldbuilding-app-skills/plugin install supabase-prisma-database-management@worldbuilding-app-skillsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/example-schema.prismaassets/github-workflows-schema-check.ymlassets/prisma-client.tsassets/seed.tsreferences/prisma-best-practices.mdreferences/supabase-integration.mdManage database schema, migrations, and seed data using Prisma ORM with Supabase PostgreSQL, including shadow database configuration, seed files, and automated schema checks in CI.
Install Prisma CLI and client:
npm install -D prisma
npm install @prisma/client
Initialize Prisma in your project:
npx prisma init
This creates:
prisma/schema.prisma - Database schema definition.env - Environment variables (add DATABASE_URL)Get your Supabase database URL from:
Add to .env:
# Transaction pooler for Prisma migrations
DATABASE_URL="postgresql://postgres:[YOUR-PASSWORD]@db.[PROJECT-REF].supabase.co:5432/postgres"
# Session pooler for queries (with pgBouncer)
DIRECT_URL="postgresql://postgres:[YOUR-PASSWORD]@db.[PROJECT-REF].supabase.co:6543/postgres?pgbouncer=true"
Update prisma/schema.prisma to use both URLs:
datasource db {
provider = "postgresql"
url = env("DIRECT_URL")
directUrl = env("DATABASE_URL")
}
Why two URLs?
DATABASE_URL: Direct connection for migrations (required)DIRECT_URL: Pooled connection for application queries (optional, better performance)For migration preview and validation, configure a shadow database in prisma/schema.prisma:
datasource db {
provider = "postgresql"
url = env("DIRECT_URL")
directUrl = env("DATABASE_URL")
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
}
Add to .env:
SHADOW_DATABASE_URL="postgresql://postgres:[PASSWORD]@db.[PROJECT-REF].supabase.co:5432/postgres"
Note: Supabase free tier allows using the same database for shadow. For production, use a separate database.
Edit prisma/schema.prisma using the example from assets/example-schema.prisma. This example includes:
@default(now()) and @updatedAtKey Prisma features:
@id @default(uuid()) - Auto-generated UUIDs@default(now()) - Automatic timestamps@updatedAt - Auto-update on modification@@index([field]) - Database indexes@relation - Define relationshipsTo integrate with Supabase Auth, reference the auth.users table:
model Profile {
id String @id @db.Uuid
email String @unique
// Other fields...
// This doesn't create a foreign key, just documents the relationship
// The actual user exists in auth.users (managed by Supabase)
}
Important: Don't create a foreign key to auth.users as it's in a different schema. Handle the relationship in application logic.
After defining/modifying schema, create a migration:
npx prisma migrate dev --name add_profiles_table
This:
prisma/migrations/Always review generated SQL in prisma/migrations/[timestamp]_[name]/migration.sql:
-- CreateTable
CREATE TABLE "Profile" (
"id" UUID NOT NULL,
"email" TEXT NOT NULL,
-- ...
CONSTRAINT "Profile_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "Profile_email_key" ON "Profile"("email");
Make manual adjustments if needed before applying to production.
For production deployments:
npx prisma migrate deploy
This applies pending migrations without prompts or seeds.
CI/CD Integration: Add to your deployment pipeline:
# Example GitHub Actions step
- name: Run migrations
run: npx prisma migrate deploy
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
To reset database to clean state:
npx prisma migrate reset
This:
Warning: This deletes all data. Only use in development.
Create prisma/seed.ts using the template from assets/seed.ts. This script:
Add seed configuration to package.json:
{
"prisma": {
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
}
}
Install ts-node for TypeScript execution:
npm install -D ts-node
Execute seed script:
npx prisma db seed
Seed runs automatically after prisma migrate dev and prisma migrate reset.
Make seeds safe to run multiple times using upsert:
await prisma.user.upsert({
where: { email: 'admin@example.com' },
update: {}, // No updates if exists
create: {
email: 'admin@example.com',
name: 'Admin User',
},
});
After schema changes, regenerate Prisma Client:
npx prisma generate
This updates node_modules/@prisma/client with types matching your schema.
Create a Prisma client singleton using assets/prisma-client.ts:
import { prisma } from '@/lib/prisma';
export default async function UsersPage() {
const users = await prisma.profile.findMany();
return (
<ul>
{users.map((user) => (
<li key={user.id}>{user.name}</li>
))}
</ul>
);
}
'use server';
import { prisma } from '@/lib/prisma';
import { revalidatePath } from 'next/cache';
export async function createProfile(formData: FormData) {
const name = formData.get('name') as string;
await prisma.profile.create({
data: {
name,
email: formData.get('email') as string,
},
});
revalidatePath('/profiles');
}
Create .github/workflows/schema-check.yml using the template from assets/github-workflows-schema-check.yml. This workflow:
Add migration step to deployment workflow:
- name: Apply database migrations
run: npx prisma migrate deploy
env:
DATABASE_URL: ${{ secrets.PROD_DATABASE_URL }}
Use different database URLs for each environment:
# Development
DATABASE_URL="postgresql://localhost:5432/dev"
# Staging
DATABASE_URL="postgresql://staging-db.supabase.co:5432/postgres"
# Production
DATABASE_URL="postgresql://prod-db.supabase.co:5432/postgres"
createdAt and updatedAtcreateMany, updateMany for bulk opsMigration fails with "relation already exists": Reset development database with npx prisma migrate reset. For production, manually fix conflicts.
Prisma Client out of sync: Run npx prisma generate after schema changes.
Connection pool exhausted: Use connection pooling via DIRECT_URL with pgBouncer.
Shadow database errors: Ensure shadow database URL is correct and accessible. For Supabase free tier, same DB can be used.
Type errors after schema changes: Restart TypeScript server in IDE after prisma generate.
No executable scripts needed for this skill.
prisma-best-practices.md - Comprehensive guide to Prisma patterns, performance optimization, and common pitfallssupabase-integration.md - Specific considerations for using Prisma with Supabase, including RLS integrationexample-schema.prisma - Complete schema example with common patterns (auth, timestamps, relations, indexes)seed.ts - Idempotent seed script template for initial dataprisma-client.ts - Singleton Prisma Client for Next.js to prevent connection exhaustiongithub-workflows-schema-check.yml - CI workflow for schema validation and migration checksUse when working with Payload CMS projects (payload.config.ts, collections, fields, hooks, access control, Payload API). Use when debugging validation errors, security issues, relationship queries, transactions, or hook behavior.
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.