Obtain or reuse a Prisma Postgres database and connect an application. Use for "set up Prisma Postgres", "connect my app to Prisma Postgres", or Prisma…
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 or Vercel Marketplace Read Marketplace setup and use the native integration flow. 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.
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/.