prisma-postgres-setup

작성자: prisma

새로운 Prisma Postgres 데이터베이스를 설정하고 Management API를 사용하여 로컬 프로젝트에 연결합니다. "데이터베이스 설정", "Prisma 생성" 요청 시 사용합니다.

npx skills add https://github.com/prisma/skills --skill prisma-postgres-setup

Prisma Postgres Setup

Procedural skill that guides you through provisioning a new Prisma Postgres database via the Management API and connecting it to a local project.

When to Apply

Use this skill when:

  • Setting up a new Prisma Postgres database for a project
  • Creating a Prisma Postgres project and connecting it locally
  • Obtaining a connection string for Prisma Postgres
  • Provisioning a database via the Management API (not the Console UI)

Do not use this skill when:

  • Setting up CI/CD preview databases — use prisma-postgres-cicd
  • Building multi-tenant database provisioning into an app — use prisma-postgres-integrator
  • Working with a database that already exists and is connected (schema/migration tasks are standard Prisma CLI)

Prerequisites

  • Node.js 18+
  • A Prisma Postgres workspace (create one at https://console.prisma.io if needed)
  • A workspace service token (see references/auth.md)

UX Guidelines

When presenting choices to the user (region selection, project deletion, etc.), use your platform's interactive selection mechanism (e.g., ask tool in Claude Code, structured prompts in other agents). Do not print static tables and ask the user to type a value — present selectable options so the user can pick with minimal effort.

Workflow

Follow these steps in order. Each step includes the API call to make and how to handle the response.

Step 1: Authenticate

You need a service token. Try these methods in order:

1a. Token in the user's prompt

Check if the user included a service token in their initial message (e.g., "Set up Prisma Postgres with token eyJ..."). If so, use it exactly as provided — do not truncate, re-encode, or round-trip it through a file. Store it in a shell variable for subsequent calls.

1b. Token in the environment

Check for PRISMA_SERVICE_TOKEN in the environment or .env file.

1c. Ask the user to create one

If no token is available, instruct the user:

Create a service token in Prisma Console → Workspace Settings → Service Tokens. Copy the token and paste it here.

Read references/auth.md for details on service token creation.

Once you have a token, store it in a shell variable (PRISMA_SERVICE_TOKEN) and use it for all subsequent API calls.

Step 2: List available regions

Fetch the list of available Prisma Postgres regions to let the user choose where to deploy.

curl -s -H "Authorization: Bearer $PRISMA_SERVICE_TOKEN" \
  https://api.prisma.io/v1/regions/postgres

The response contains an array of regions with id, name, and status. Only present regions where status is available.

Present the regions as an interactive menu — let the user pick from options rather than typing a region ID manually.

Read references/endpoints.md for the full response shape.

Step 3: Create a project with a 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
  }'

Use the current directory name as the project name by default.

The response is wrapped in { "data": { ... } }. Extract:

  • data.id — the project ID (prefixed with proj_)
  • data.database.id — the database ID (prefixed with db_)
  • data.database.connections[0].endpoints.direct.connectionString — the direct PostgreSQL connection string

Use the direct connection string (endpoints.direct.connectionString). Do not use the pooled or accelerate endpoints — those are for legacy Accelerate setups and not needed for new projects.

If the response status is provisioning, wait a few seconds and poll GET /v1/databases/<database-id> until status is ready.

If creation fails due to a database limit, list the user's existing projects and present them as an interactive menu for deletion. After the user picks one, delete it and retry.

Read references/endpoints.md for the full request/response shapes.

Step 4: Create a named connection (optional)

If you need a dedicated connection (e.g., per-developer or per-environment), create one:

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": "dev" }'

Extract the direct connection string from data.endpoints.direct.connectionString.

Step 5: Configure the local project

  1. Install dependencies:
npm install prisma @prisma/client @prisma/adapter-pg pg dotenv

All five packages are required:

  • prisma — CLI for migrations, schema push, client generation
  • @prisma/client — the generated query client
  • @prisma/adapter-pg — Prisma 7 driver adapter for direct PostgreSQL connections
  • pg — Node.js PostgreSQL driver (used by the adapter)
  • dotenv — loads .env variables for prisma.config.ts
  1. Write the direct connection string to .env. Append to the file if it already exists — do not overwrite existing entries:
DATABASE_URL="<direct-connection-string>"
  1. Verify .gitignore includes .env. Create .gitignore if it does not exist. Warn the user if .env is not gitignored.

  2. Ensure package.json has "type": "module" set (Prisma 7 generates ESM output).

  3. If prisma/schema.prisma does not exist, run npx prisma init to scaffold the project. This creates both prisma/schema.prisma and prisma.config.ts.

  4. Ensure schema.prisma has the postgresql provider and no url or directUrl in the datasource block (Prisma 7 manages connection URLs in prisma.config.ts, not in the schema):

datasource db {
  provider = "postgresql"
}
  1. Ensure prisma.config.ts loads the connection URL from the environment:
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!,
  },
})

Important Prisma 7 notes:

  • Connection URLs go in prisma.config.ts, never in schema.prisma
  • The provider in schema.prisma must be "postgresql" (not "prismaPostgres")
  • dotenv/config must be imported in prisma.config.ts to load .env variables

Step 6: Define schema and push

If the schema already has models, skip to pushing. Otherwise, present these options as an interactive menu:

  1. "I'll define my schema manually" — Tell the user to edit prisma/schema.prisma and come back when ready. Wait for them before proceeding.
  2. "Give me a starter schema" — Add a Blog starter schema (User, Post, Comment with relations) to prisma/schema.prisma. Show the user what was added and ask if they want to adjust it before pushing.
  3. "I'll describe what I need" — Ask the user to describe their data model in natural language (e.g., "I'm building a task manager with projects, tasks, and team members"). Generate a schema from the description, show it, and ask for confirmation before pushing.

Once the schema has models and the user is ready, create a migration and generate the client:

npx prisma migrate dev --name init

This creates migration files in prisma/migrations/ and generates the client in one step. Migration history is essential for CI/CD workflows (prisma migrate deploy) and production deployments.

Only use npx prisma db push if the user explicitly asks for prototyping-only mode (no migration history). In that case, follow it with npx prisma generate.

Step 7: Verify the connection

After generating the client, create and run a quick verification script to confirm everything works end-to-end. This is critical — do not skip this step.

Create a file named test-connection.ts:

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()

Run it:

npx tsx test-connection.ts

Prisma 7 client instantiation rules:

  • Import from ./generated/prisma/client.js (not ./generated/prisma)
  • Create a pg.Pool with the DATABASE_URL connection string
  • Wrap it in a PrismaPg adapter
  • Pass { adapter } to the PrismaClient constructor
  • Do not use datasourceUrl — that option does not exist in Prisma 7
  • Do not use new PrismaClient() with no arguments — it will throw

After verification succeeds, delete test-connection.ts.

Then share links for the user to explore their database:

  • Prisma Studio (CLI): npx prisma studio — opens a visual data browser locally
  • Console: https://console.prisma.io/<workspaceId>/<projectId>/<databaseId>/dashboard — strip the prefixes (wksp_, proj_, db_) from the IDs returned in Step 3 to build this URL

Read references/prisma7-client.md for the full client instantiation reference.

Error Handling

Read references/api-basics.md for the full error reference. Key self-correction patterns:

HTTP StatusError CodeAction
401authentication-failedService token is invalid or expired. Ask the user to create a new one in Console → Workspace Settings → Service Tokens.
404resource-not-foundCheck that the resource ID includes the correct prefix (proj_, db_, con_).
422validation-errorCheck request body against the endpoint schema. Common: missing name, invalid region.
429rate-limit-exceededBack off and retry after a few seconds.

Reference Files

Detailed API and usage information is in:

references/auth.md             — Service token creation and usage
references/api-basics.md       — Base URL, envelope, IDs, errors, pagination
references/endpoints.md        — Endpoint details for projects, databases, connections, regions
references/prisma7-client.md   — Prisma 7 client instantiation and usage patterns

prisma의 다른 스킬

prisma-cli-migrate-reset
prisma
prisma 마이그레이션 리셋
official
prisma-cli-validate
prisma
prisma 검증. 이 Prisma 기능을 사용할 때 참조하세요.
official
prisma-next-extension-upgrade
prisma
Upgrade Prisma Next in your extension. Bumps every `@prisma-next/*` dependency to the requested target (or npm `latest`), runs the per-transition upgrade…
official
adr-review
prisma
하나 이상의 ADR을 새로운 시각으로(사전 맥락이 없는 팀원으로서) 검토하고, 서사 및 구조적 문제를 식별한 후 재작성합니다. 다음과 같은 경우에 사용하세요…
official
prisma-next-upgrade
prisma
Upgrade Prisma Next in your app. Bumps every `@prisma-next/*` dependency from the version pinned in the lockfile to the requested target (or npm `latest`),…
official
prisma-cli
prisma
Prisma CLI 명령어, 옵션, 워크플로우에 대한 완전한 참조로, 설정, 마이그레이션, 데이터베이스 작업 전반을 다룹니다. 우선순위별로 정리된 20개 이상의 명령어를 포함합니다: 설정(init), 생성(generate), 개발(dev), 데이터베이스 작업(db pull/push/seed/execute), 마이그레이션(migrate dev/deploy/reset/status/diff/resolve). Prisma 7.x 변경 사항을 포함합니다: 새로운 prisma.config.ts 설정 파일, 제거된 플래그(--skip-generate, --skip-seed, --schema, --url), 명시적...
official
prisma-client-api
prisma
Prisma Client API 전체 참조: 모델 쿼리, CRUD 작업, 필터링, 관계 및 트랜잭션. findUnique, findMany, create, update, delete, upsert 및 반환 변형이 있는 대량 작업을 포함한 17가지 모델 쿼리 메서드를 다룹니다. select, include, omit, orderBy, take, skip, cursor 및 distinct를 포함한 결과 형태를 지정하는 쿼리 옵션을 제공합니다. equals, in, contains, startsWith, lt, gt와 같은 스칼라 및 논리 필터 연산자와 some,...을 포함한 관계 필터를 포함합니다.
official
prisma-compute
prisma
Prisma Compute deployment and hosting guide. Use whenever the user mentions Prisma Compute, `prisma.compute.ts`, `defineComputeConfig`, deploying or hosting a Prisma app, `@prisma/cli app deploy`, `compute:deploy`, `create-prisma --deploy`, `PRISMA_SERVICE_TOKEN`, `auth workspace`, Compute apps/deployments/build logs/domains, `@prisma/cli agent install`, localhost vs `0.0.0.0`, deploy port binding, or framework deploy readiness for Hono, Elysia, Next.js, TanStack Start, Astro, Nuxt, Svelte,...
developmentdevopsofficial