Loading...
Loading...
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.
npx skill4agent add hopeoverture/worldbuilding-app-skills supabase-prisma-database-managementnpm install -D prisma
npm install @prisma/clientnpx prisma initprisma/schema.prisma.envDATABASE_URL.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"prisma/schema.prismadatasource db {
provider = "postgresql"
url = env("DIRECT_URL")
directUrl = env("DATABASE_URL")
}DATABASE_URLDIRECT_URLprisma/schema.prismadatasource db {
provider = "postgresql"
url = env("DIRECT_URL")
directUrl = env("DATABASE_URL")
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
}.envSHADOW_DATABASE_URL="postgresql://postgres:[PASSWORD]@db.[PROJECT-REF].supabase.co:5432/postgres"prisma/schema.prismaassets/example-schema.prisma@default(now())@updatedAt@id @default(uuid())@default(now())@updatedAt@@index([field])@relationauth.usersmodel 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)
}auth.usersnpx prisma migrate dev --name add_profiles_tableprisma/migrations/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");npx prisma migrate deploy# Example GitHub Actions step
- name: Run migrations
run: npx prisma migrate deploy
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}npx prisma migrate resetprisma/seed.tsassets/seed.tspackage.json{
"prisma": {
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
}
}npm install -D ts-nodenpx prisma db seedprisma migrate devprisma migrate resetawait prisma.user.upsert({
where: { email: 'admin@example.com' },
update: {}, // No updates if exists
create: {
email: 'admin@example.com',
name: 'Admin User',
},
});npx prisma generatenode_modules/@prisma/clientassets/prisma-client.tsimport { 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');
}.github/workflows/schema-check.ymlassets/github-workflows-schema-check.yml- name: Apply database migrations
run: npx prisma migrate deploy
env:
DATABASE_URL: ${{ secrets.PROD_DATABASE_URL }}# 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"createdAtupdatedAtcreateManyupdateManynpx prisma migrate resetnpx prisma generateDIRECT_URLprisma generateprisma-best-practices.mdsupabase-integration.mdexample-schema.prismaseed.tsprisma-client.tsgithub-workflows-schema-check.yml