Obtain or reuse a Prisma Postgres database and connect an application. Use when the user needs a database and has none configured ("I need a database", "add a…
Prisma Postgres setup Connect the intended database, then verify it from the application. Keep provisioning separate from ORM configuration so an existing database is reused. 1. Inspect the project Check the user's requested ORM or driver, installed packages, database connection, and environment-loading files. Check secret presence without printing values. Honor explicit choices such as Drizzle, pg, or database-only setup. For query or schema work in an already configured app, use its version-matched ORM guidance; do not restart setup. 2. Reuse or obtain a database Situation Action Existing connection or connected integration Verify its project, database, and environment; reuse it. v0, Vercel Marketplace, or a Vercel project Read Marketplace setup and use the native integration flow. No database yet and no provider named Offer npx create-db@latest for a working database now with no account (it is deleted after 24 hours unless claimed, and claiming needs a free Prisma account; read the create-db section in provisioning), or a persistent database through provisioning. Ask which one when the request does not say. Standalone persistent database Read provisioning; use an authenticated CLI, MCP tool, Console, or Management API. Temporary development database requested Read the create-db section in provisioning, including expiry and claiming. Resolve the workspace, project, and region before creation. If several resources fit, ask which one to use. If provisioning is blocked by permissions or quota, report the blocker; do not delete another resource or switch workspaces to get around it. 3. Connect the application Use the connection appropriate to the chosen driver and runtime. Store it in the project's secret environment configuration, never source code or chat. Preserve unrelated entries, update the intended variable once, and ensure local secret files are ignored by Git. Application processes and CLI commands may load different environment files. For example, a framework may load .env.development.local while a shell command does not. A variable missing from the shell does not mean the database is missing: load the intended file for that command without displaying credentials, and do not provision another database. 4. Configure the ORM and verify For Prisma ORM setup, read prisma-orm-setup/SKILL.md directly, or load the installed prisma-orm-setup skill when the host resolves sibling skills by name. It owns ORM version selection and configuration. If that handoff is unavailable, report it. For an explicitly selected alternative, keep that ORM or driver and use its documented setup. For database-only setup, stop after verifying connectivity. Run a read-only query against the intended database through the application's chosen ORM or driver. Report what was connected, the selected ORM/version, and the query result without secrets. If any step is blocked or untested, say so instead of claiming setup is complete. For Studio, SDK integrations, or database operations beyond initial setup, read operations.
don't have the plugin yet? install it then click "run inline in claude" again.
extracted decision logic into explicit if-else branches, added edge cases (rate limits, auth expiry, provisioning delays, database limits), documented all external connections and environment variables, reorganized procedure into numbered steps with clear inputs/outputs, and added outcome signal for user verification.
Set up a new Prisma Postgres database via the Management API and connect it to a local project. use this skill when provisioning a fresh database, creating a new Prisma Postgres project, obtaining connection strings, or integrating database setup into a workflow. do not use this for existing connected databases (schema and migration tasks are standard Prisma CLI), CI/CD preview databases (use prisma-postgres-cicd), or multi-tenant provisioning at app scale (use prisma-postgres-integrator).
edge cases to handle: token expiry (401 errors), rate limits (429), database creation limits (existing databases must be deleted first), network timeouts, and provisioning delays (polling required for status checks).
step 1: authenticate with service token
export PRISMA_SERVICE_TOKEN="<token>".step 2: list available regions
curl -s -H "Authorization: Bearer $PRISMA_SERVICE_TOKEN" https://api.prisma.io/v1/regions/postgresstatus is available.step 3: create project with database
curl -s -X POST https://api.prisma.io/v1/projects -H "Authorization: Bearer $PRISMA_SERVICE_TOKEN" -H "Content-Type: application/json" -d '{"name":"<project-name>","region":"<region-id>","createDatabase":true}'data.id (project ID, prefixed proj_), data.database.id (database ID, prefixed db_), and data.database.connections[0].endpoints.direct.connectionString (direct PostgreSQL connection string).provisioning, poll GET /v1/databases/<database-id> every 2-3 seconds until status is ready.step 4: create named connection (optional)
curl -s -X POST https://api.prisma.io/v1/databases/<database-id>/connections -H "Authorization: Bearer $PRISMA_SERVICE_TOKEN" -H "Content-Type: application/json" -d '{"name":"<connection-name>"}'data.endpoints.direct.connectionString.step 5: configure local project
npm install prisma @prisma/client @prisma/adapter-pg pg dotenv. all five packages are required.DATABASE_URL="<direct-connection-string>"."type": "module" in package.json (Prisma 7 generates ESM output).npx prisma init. this scaffolds prisma/schema.prisma and prisma.config.ts.datasource db {
provider = "postgresql"
}
import path from 'node:path'
import { defineConfig } from 'prisma/config'
import 'dotenv/config'
export default defineConfig({
earlyAccess: true,
schema: path.join(import.meta.dirname, 'prisma', 'schema.prisma'),
datasource: {
url: process.env.DATABASE_URL!,
},
})
step 6: define schema and push
npx prisma migrate dev --name init.step 7: verify connection
import 'dotenv/config'
import pg from 'pg'
import { PrismaPg } from '@prisma/adapter-pg'
import { PrismaClient } from './generated/prisma/client.js'
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL })
const adapter = new PrismaPg(pool)
const prisma = new PrismaClient({ adapter })
const result = await prisma.$queryRawUnsafe('SELECT 1 as connected')
console.log('Connected to Prisma Postgres:', result)
await prisma.$disconnect()
await pool.end()
npx tsx test-connection.ts.npx prisma studio) and Console dashboard (https://console.prisma.io/<workspaceId>/<projectId>/<databaseId>/dashboard, strip prefixes wksp_, proj_, db_ from IDs).if service token not found: ask user to create one in Console → Workspace Settings → Service Tokens and paste it. do not proceed without token.
if region list is empty or no available regions: inform user that the workspace has no available Postgres regions. suggest creating a new workspace or contacting support.
if project creation returns HTTP 422 validation-error: check request body matches endpoint schema. common issues: missing name, invalid region ID. re-prompt user.
if project creation returns HTTP 429 rate-limit-exceeded: back off and retry after 3-5 seconds. inform user of retry attempt.
if database provisioning status is not ready immediately: poll GET /v1/databases/
if HTTP 401 authentication-failed: service token is invalid or expired. ask user to create a new one in Console → Workspace Settings → Service Tokens.
if project creation fails with database limit error: list user's existing projects via GET /v1/projects as interactive menu. let user pick one to delete. call DELETE /v1/projects/
if schema already has models in step 6: skip to running npx prisma migrate dev --name init directly.
if user explicitly requests prototyping-only mode (no migration history): use npx prisma db push instead of migrate dev, then run npx prisma generate separately. warn user that migration history will not be tracked.
if test-connection.ts fails with connection error: check DATABASE_URL is correct and database is ready. verify pg.Pool is initialized. ensure PrismaPg adapter is instantiated. do not delete test-connection.ts until connection succeeds.
DATABASE_URL="<direct-connection-string>". file exists in project root and is gitignored.<project>/prisma/schema.prisma.<project>/prisma.config.ts.<timestamp>_init. location: <project>/prisma/migrations/<timestamp>_init/migration.sql.<project>/generated/prisma/client.js (ESM output)."type": "module" and dependencies: prisma, @prisma/client, @prisma/adapter-pg, pg, dotenv.user can:
npx prisma studio and see their database tables and data in the local web UI.https://console.prisma.io/<workspaceId>/<projectId>/<databaseId>/dashboard and see the database online in Prisma Console.import { PrismaClient } from './generated/prisma/client.js') and execute queries without connection errors.npx prisma migrate dev in the future and see migration history tracked in prisma/migrations/.