### Start existing instance Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/dev.md Starts a previously created instance in the background. ```bash prisma dev start myproject ``` -------------------------------- ### Install Prisma Driver Adapters Source: https://context7.com/prisma/skills/llms.txt Install the appropriate driver adapter for your database provider using npm. Examples are provided for PostgreSQL, MySQL, SQLite, and SQL Server. ```bash # PostgreSQL / CockroachDB / Prisma Postgres (Node.js) npm install @prisma/adapter-pg pg # Prisma Postgres (edge/serverless) npm install @prisma/adapter-ppg @prisma/ppg # MySQL / MariaDB npm install @prisma/adapter-mariadb mariadb # SQLite npm install @prisma/adapter-better-sqlite3 better-sqlite3 # SQLite (Turso/LibSQL) npm install @prisma/adapter-libsql @libsql/client # SQL Server npm install @prisma/adapter-mssql node-mssql # Neon npm install @prisma/adapter-neon ``` -------------------------------- ### Run prisma generate examples Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/generate.md Various command-line examples for generating assets. ```bash prisma generate ``` ```bash prisma generate --watch ``` ```bash prisma generate --generator client ``` ```bash prisma generate --generator client --generator zod_schemas ``` ```bash prisma generate --sql ``` -------------------------------- ### Install Prisma CLI and Client Source: https://github.com/prisma/skills/blob/main/prisma-database-setup/SKILL.md Standard installation commands for the Prisma CLI and the Prisma Client library. ```bash npm install prisma --save-dev npm install @prisma/client ``` -------------------------------- ### Install create-db library Source: https://github.com/prisma/skills/blob/main/prisma-postgres/references/create-db-cli.md Installation commands for using create-db programmatically in Node.js or Bun environments. ```bash npm install create-db # or bun add create-db ``` -------------------------------- ### Install SQLite Adapter Source: https://github.com/prisma/skills/blob/main/prisma-upgrade-v7/references/driver-adapters.md Install the SQLite driver adapter. ```bash npm install @prisma/adapter-better-sqlite3 ``` -------------------------------- ### Workflow: Starting from Existing Database Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/db-pull.md Steps to initialize Prisma, configure the database URL, pull the schema, and generate the Prisma client when starting with an existing database. ```bash prisma init ``` ```bash prisma db pull ``` ```bash prisma generate ``` -------------------------------- ### Full Prisma configuration example Source: https://github.com/prisma/skills/blob/main/prisma-upgrade-v7/references/prisma-config.md Comprehensive example including schema, migrations, and all datasource connection types. ```typescript import 'dotenv/config' import { defineConfig, env } from 'prisma/config' export default defineConfig({ // Schema location schema: 'prisma/schema.prisma', // Migration configuration migrations: { path: 'prisma/migrations', seed: 'tsx prisma/seed.ts', }, // Database connection datasource: { url: env('DATABASE_URL'), directUrl: env('DIRECT_DATABASE_URL'), shadowDatabaseUrl: env('SHADOW_DATABASE_URL'), }, }) ``` -------------------------------- ### Install Serverless PG Adapter Source: https://github.com/prisma/skills/blob/main/prisma-database-setup/references/prisma-postgres.md Install the npm packages for the @prisma/adapter-ppg and @prisma/ppg for serverless environments. ```bash npm install @prisma/adapter-ppg @prisma/ppg ``` -------------------------------- ### Install PostgreSQL Adapter Source: https://github.com/prisma/skills/blob/main/prisma-upgrade-v7/references/driver-adapters.md Install the PostgreSQL driver adapter package. ```bash npm install @prisma/adapter-pg ``` -------------------------------- ### Install Prisma Client and PostgreSQL Adapter Source: https://github.com/prisma/skills/blob/main/prisma-postgres-setup/references/prisma7-client.md Install the necessary packages for Prisma Client and the PostgreSQL driver adapter. ```bash npm install @prisma/client @prisma/adapter-pg pg ``` -------------------------------- ### Start local database Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/dev.md Starts the local database instance in the current terminal. ```bash prisma dev ``` -------------------------------- ### Install Prisma Skills Source: https://context7.com/prisma/skills/llms.txt Use 'npx skills add' to install all Prisma skills or specific ones. Use '--list' to see available skills. ```bash npx skills add prisma/skills ``` ```bash npx skills add prisma/skills --skill prisma-cli ``` ```bash npx skills add prisma/skills --skill prisma-client-api ``` ```bash npx skills add prisma/skills --skill prisma-upgrade-v7 ``` ```bash npx skills add prisma/skills --list ``` ```bash npx skills list ``` -------------------------------- ### Install Prisma Management API SDK Source: https://github.com/prisma/skills/blob/main/prisma-postgres/references/management-api-sdk.md Install the SDK using npm. This is the first step to integrate with the Prisma Management API. ```bash npm install @prisma/management-api-sdk ``` -------------------------------- ### Prisma Migrate Status Output Examples Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/migrate-status.md Example outputs showing the database state when up to date or when migrations are pending. ```text Database schema is up to date! ``` ```text Following migration have not yet been applied: 20240115120000_add_user To apply migrations in development, run: prisma migrate dev To apply migrations in production, run: prisma migrate deploy ``` -------------------------------- ### Start named database instance Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/dev.md Starts a database instance with a specific name, useful for managing multiple projects. ```bash prisma dev --name myproject ``` -------------------------------- ### Prisma CLI Quick Reference - Project Setup Source: https://context7.com/prisma/skills/llms.txt Initialize a new Prisma project or set up Prisma with a specific datasource provider using `npx prisma init`. ```bash # Project setup npx prisma init npx prisma init --datasource-provider sqlite npx prisma init --db # Prisma Postgres cloud ``` -------------------------------- ### Configure PrismaClient with Driver Adapters Source: https://context7.com/prisma/skills/llms.txt Configure PrismaClient by instantiating the appropriate driver adapter for your database. Examples show setup for PostgreSQL, MySQL, and SQLite. ```typescript // PostgreSQL example import { PrismaClient } from '../generated/prisma/client' import { PrismaPg } from '@prisma/adapter-pg' const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }) const prisma = new PrismaClient({ adapter }) ``` ```typescript // MySQL example import { PrismaMariaDB } from '@prisma/adapter-mariadb' const adapter = new PrismaMariaDB({ connectionString: process.env.DATABASE_URL }) ``` ```typescript // SQLite example import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3' const adapter = new PrismaBetterSQLite3({ url: 'file:./dev.db' }) ``` -------------------------------- ### Install dotenv Source: https://github.com/prisma/skills/blob/main/prisma-upgrade-v7/references/env-variables.md Install the dotenv package to manage environment variables. ```bash npm install dotenv ``` -------------------------------- ### Common CLI usage patterns Source: https://github.com/prisma/skills/blob/main/prisma-postgres/references/create-db-cli.md Examples of common CLI flags for database provisioning tasks. ```bash # quick database npx create-db@latest # region-specific database npx create-db@latest --region eu-central-1 # interactive region selection npx create-db@latest --interactive # write env vars for app bootstrap npx create-db@latest --env .env # auto-delete sooner npx create-db@latest --ttl 2h # copy connection string to clipboard npx create-db@latest --copy # print only the connection string npx create-db@latest --quiet # CI-friendly output npx create-db@latest --json ``` -------------------------------- ### Install Accelerate Extension Source: https://github.com/prisma/skills/blob/main/prisma-upgrade-v7/references/accelerate-users.md Install the required extension package via npm. ```bash npm install @prisma/extension-accelerate ``` -------------------------------- ### Initialize Prisma Project Source: https://context7.com/prisma/skills/llms.txt Bootstrap a new Prisma project using 'npx prisma init'. Specify the datasource provider or use '--db' for Prisma Postgres. '--with-model' initializes with an example model. Use 'bunx --bun prisma init' for Bun runtime. ```bash npx prisma init ``` ```bash npx prisma init --datasource-provider postgresql ``` ```bash npx prisma init --datasource-provider mysql ``` ```bash npx prisma init --datasource-provider sqlite ``` ```bash npx prisma init --db ``` ```bash npx prisma init --with-model ``` ```bash bunx --bun prisma init ``` -------------------------------- ### Install LibSQL/Turso Adapter and Driver Source: https://github.com/prisma/skills/blob/main/prisma-database-setup/references/sqlite.md Installs the npm packages required for using the LibSQL driver adapter for edge compatibility or Turso. ```bash npm install @prisma/adapter-libsql @libsql/client ``` -------------------------------- ### Install Specific Prisma Skill Source: https://github.com/prisma/skills/blob/main/README.md Installs a specific Prisma skill, such as prisma-cli. ```bash npx skills add prisma/skills --skill prisma-cli ``` ```bash npx skills add prisma/skills --skill prisma-upgrade-v7 ``` ```bash npx skills add prisma/skills --skill prisma-client-api ``` ```bash npx skills add prisma/skills --skill prisma-driver-adapter-implementation ``` ```bash npx skills add prisma/skills --skill prisma-database-setup ``` ```bash npx skills add prisma/skills --skill prisma-postgres ``` -------------------------------- ### Pagination Examples Source: https://github.com/prisma/skills/blob/main/prisma-postgres-setup/references/api-basics.md Examples of API requests demonstrating cursor-based pagination. Use the `cursor` parameter with `nextCursor` from the previous response. ```http GET /v1/projects?limit=10 ``` ```http GET /v1/projects?cursor=clx7abc123&limit=10 ``` -------------------------------- ### Install Skill Locally (OpenCode) Source: https://github.com/prisma/skills/blob/main/AGENTS.md Command to copy a skill directory to the local OpenCode skills directory for testing. ```bash cp -r skills/prisma-{skill-name} ~/.config/opencode/skill/ ``` -------------------------------- ### Example Agent Prompts for Prisma Skills Source: https://github.com/prisma/skills/blob/main/README.md Examples of natural language prompts that can trigger Prisma skills. ```bash Help me run Prisma migrations in production ``` ```bash Upgrade my project from Prisma 6 to Prisma 7 ``` ```bash How do I use transactions in Prisma? ``` -------------------------------- ### Install Skill via CLI Source: https://github.com/prisma/skills/blob/main/AGENTS.md Command to add a Prisma skill repository using the skills CLI. ```bash npx skills add prisma/skills ``` -------------------------------- ### Install better-sqlite3 Adapter and Driver Source: https://github.com/prisma/skills/blob/main/prisma-database-setup/references/sqlite.md Installs the necessary npm packages for using the better-sqlite3 driver adapter with Prisma. ```bash npm install @prisma/adapter-better-sqlite3 better-sqlite3 ``` -------------------------------- ### Instantiate PrismaClient with Adapter Source: https://github.com/prisma/skills/blob/main/prisma-client-api/references/constructor.md Basic setup using a driver adapter for SQL providers. ```typescript import { PrismaClient } from '../generated/client' import { PrismaPg } from '@prisma/adapter-pg' const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }) const prisma = new PrismaClient({ adapter }) ``` ```typescript import { PrismaPg } from '@prisma/adapter-pg' const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }) const prisma = new PrismaClient({ adapter }) ``` -------------------------------- ### Start database with custom ports Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/dev.md Overrides default HTTP and database server ports. ```bash prisma dev --port 5000 --db-port 5432 ``` -------------------------------- ### View generated output structure Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/generate.md Example of the file structure created after running the command. ```text generated/ ├── browser.ts ├── client.ts ├── commonInputTypes.ts ├── models/ ├── enums.ts ├── models.ts └── ... ``` -------------------------------- ### Development workflow commands Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/dev.md Standard sequence of commands for starting the database, running migrations, and generating the client. ```bash prisma dev ``` ```bash prisma migrate dev ``` ```bash prisma generate ``` -------------------------------- ### Run prisma dev command Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/dev.md Basic command to start a local Prisma Postgres database. ```bash prisma dev [options] ``` -------------------------------- ### Install PostgreSQL Driver Adapter and Driver Source: https://github.com/prisma/skills/blob/main/prisma-database-setup/references/cockroachdb.md Install the necessary npm packages for the PostgreSQL driver adapter and the pg driver to enable standard SQL workflows. ```bash npm install @prisma/adapter-pg pg ``` -------------------------------- ### Install MSSQL Driver Adapter and Driver Source: https://github.com/prisma/skills/blob/main/prisma-database-setup/references/sqlserver.md Install the necessary npm packages for the MSSQL driver adapter and the mssql driver. ```bash npm install @prisma/adapter-mssql mssql ``` -------------------------------- ### List Available Prisma Skills Source: https://github.com/prisma/skills/blob/main/README.md Lists all Prisma skills that are available for installation. ```bash npx skills add prisma/skills --list ``` -------------------------------- ### Install MariaDB Adapter and Driver Source: https://github.com/prisma/skills/blob/main/prisma-database-setup/references/mysql.md Install the necessary npm packages for the MariaDB driver adapter. This is required for using Prisma with MariaDB in a standard SQL workflow. ```bash npm install @prisma/adapter-mariadb mariadb ``` -------------------------------- ### Install SQL Driver Adapters for Prisma Source: https://github.com/prisma/skills/blob/main/prisma-upgrade-v7/SKILL.md Install the necessary npm packages for Prisma driver adapters based on your SQL database provider. For MongoDB, do not upgrade to Prisma 7.x. ```bash # PostgreSQL npm install @prisma/adapter-pg pg # MySQL npm install @prisma/adapter-mariadb mariadb # SQLite npm install @prisma/adapter-better-sqlite3 better-sqlite3 # Prisma Postgres in standard Node.js apps (recommended) npm install @prisma/adapter-pg pg # Prisma Postgres serverless driver (edge/serverless) npm install @prisma/adapter-ppg @prisma/ppg # Neon npm install @prisma/adapter-neon ``` -------------------------------- ### Prisma Output Path - Standard Project Source: https://github.com/prisma/skills/blob/main/prisma-upgrade-v7/references/schema-changes.md Example of a standard output path for generated Prisma Client files. ```prisma output = "../generated/prisma" ``` -------------------------------- ### Prisma Seed Script Example Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/db-seed.md An example Prisma seed script that creates users and posts using `upsert` for idempotency. Ensure you have generated the client with `prisma generate`. ```typescript // prisma/seed.ts import { PrismaClient } from '../generated/client' const prisma = new PrismaClient() async function main() { // Create users const alice = await prisma.user.upsert({ where: { email: 'alice@prisma.io' }, update: {}, create: { email: 'alice@prisma.io', name: 'Alice', posts: { create: { title: 'Hello World', published: true, }, }, }, }) const bob = await prisma.user.upsert({ where: { email: 'bob@prisma.io' }, update: {}, create: { email: 'bob@prisma.io', name: 'Bob', }, }) console.log({ alice, bob }) } main() .then(async () => { await prisma.$disconnect() }) .catch(async (e) => { console.error(e) await prisma.$disconnect() process.exit(1) }) ``` -------------------------------- ### Prisma CLI Quick Reference - Local Development Database Source: https://context7.com/prisma/skills/llms.txt Manage local development databases with `prisma dev`. Commands include starting, detaching, listing, and stopping development databases. ```bash # Local development database npx prisma dev npx prisma dev --name myproject npx prisma dev --detach npx prisma dev ls npx prisma dev stop myproject ``` -------------------------------- ### Migration Directory Structure Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/migrate-dev.md Example of the file structure generated within the prisma/migrations folder. ```text prisma/migrations/ ├── 20240115120000_add_users_table/ │ └── migration.sql ├── 20240116090000_add_posts/ │ └── migration.sql └── migration_lock.toml ``` -------------------------------- ### SQL Table Definitions Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/db-pull.md Example SQL definitions for `users` and `posts` tables, illustrating the source structure before introspection. ```sql -- Database tables CREATE TABLE users ( id SERIAL PRIMARY KEY, email VARCHAR(255) UNIQUE NOT NULL, name VARCHAR(100) ); CREATE TABLE posts ( id SERIAL PRIMARY KEY, title VARCHAR(255) NOT NULL, author_id INTEGER REFERENCES users(id) ); ``` -------------------------------- ### Initialize Prisma project Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/init.md Basic command to bootstrap a new Prisma project. ```bash prisma init [options] ``` ```bash bunx --bun prisma init ``` ```bash prisma init ``` ```bash prisma init --datasource-provider sqlite ``` ```bash prisma init --datasource-provider mysql --url "mysql://user:password@localhost:3306/mydb" ``` ```bash prisma init --db ``` ```bash prisma init --with-model ``` ```bash prisma init --preview-feature relationJoins --preview-feature fullTextSearch ``` -------------------------------- ### Prisma Output Path - Monorepo Source: https://github.com/prisma/skills/blob/main/prisma-upgrade-v7/references/schema-changes.md Example of an output path configuration for a monorepo setup. ```prisma output = "../../packages/database/generated/prisma" ``` -------------------------------- ### Configure Prisma CLI Source: https://github.com/prisma/skills/blob/main/prisma-cli/SKILL.md Example configuration using prisma.config.ts to define schema paths, migration settings, and datasource URLs. ```typescript import 'dotenv/config' import { defineConfig, env } from 'prisma/config' export default defineConfig({ schema: 'prisma/schema.prisma', migrations: { path: 'prisma/migrations', seed: 'tsx prisma/seed.ts', }, datasource: { url: env('DATABASE_URL'), }, }) ``` -------------------------------- ### Initialize migrations and client Source: https://github.com/prisma/skills/blob/main/prisma-postgres-setup/SKILL.md Create migration files and generate the Prisma client. ```bash npx prisma migrate dev --name init ``` -------------------------------- ### Prisma Management API - Create Project Source: https://context7.com/prisma/skills/llms.txt Example using curl to create a new project with a database via the Prisma Management API. Requires authentication and a JSON payload. ```bash curl -X POST https://api.prisma.io/v1/projects \ -H "Authorization: Bearer $PRISMA_SERVICE_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "name": "my-project", "region": "us-east-1", "createDatabase": true }' ``` -------------------------------- ### Open Studio Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/studio.md Launches the Studio interface at the default port. ```bash prisma studio ``` -------------------------------- ### Install Skill Locally (Claude Code) Source: https://github.com/prisma/skills/blob/main/AGENTS.md Command to copy a skill directory to the local Claude Code skills directory for testing. ```bash cp -r skills/prisma-{skill-name} ~/.claude/skills/ ``` -------------------------------- ### Initialize Prisma Project Source: https://github.com/prisma/skills/blob/main/prisma-cli/SKILL.md Commands to bootstrap a new Prisma project with various database providers or cloud options. ```bash # Initialize new project (creates prisma/ folder and prisma.config.ts) prisma init # Initialize with specific database prisma init --datasource-provider postgresql prisma init --datasource-provider mysql prisma init --datasource-provider sqlite # Initialize with Prisma Postgres (cloud) prisma init --db # Initialize with an example model prisma init --with-model ``` -------------------------------- ### List Installed Prisma Skills Source: https://github.com/prisma/skills/blob/main/README.md Lists all Prisma skills that have been installed for the agent. ```bash npx skills list ``` -------------------------------- ### Provision a database with create-db Source: https://github.com/prisma/skills/blob/main/prisma-postgres/SKILL.md Use these commands to quickly provision a new database instance. ```bash npx create-db@latest ``` ```bash npx create-pg@latest ``` ```bash npx create-postgres@latest ``` -------------------------------- ### Initialize production migration Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/dev.md Prepares the project to switch to Prisma Postgres cloud. ```bash prisma init --db ``` -------------------------------- ### Create Project with Database Source: https://github.com/prisma/skills/blob/main/prisma-postgres-setup/references/endpoints.md Initiates the creation of a new project and optionally a default database. The response includes connection details, including the direct connection string for the database. ```json { "name": "my-project", "region": "us-east-1", "createDatabase": true } ``` ```json { "data": { "id": "proj_clx7abc123", "type": "project", "url": "https://api.prisma.io/v1/projects/proj_clx7abc123", "name": "my-project", "createdAt": "2025-06-15T10:30:00.000Z", "defaultRegion": "us-east-1", "workspace": { "id": "wksp_xyz789", "url": "https://api.prisma.io/v1/workspaces/wksp_xyz789", "name": "My Workspace" }, "database": { "id": "db_def456", "type": "database", "url": "https://api.prisma.io/v1/databases/db_def456", "name": "my-project", "status": "ready", "createdAt": "2025-06-15T10:30:00.000Z", "isDefault": true, "defaultConnectionId": "con_ghi789", "connections": [ { "id": "con_ghi789", "type": "connection", "url": "https://api.prisma.io/v1/connections/con_ghi789", "name": "Default", "createdAt": "2025-06-15T10:30:00.000Z", "kind": "postgres", "endpoints": { "direct": { "host": "db.prisma.io", "port": 5432, "connectionString": "postgres://user:pass@db.prisma.io:5432/postgres?sslmode=require" } } } ], "region": { "id": "us-east-1", "name": "US East (N. Virginia)" } } } } ``` -------------------------------- ### Configure Prisma Generator with Multiple Options Source: https://github.com/prisma/skills/blob/main/prisma-upgrade-v7/references/esm-support.md Example of configuring the Prisma Client generator with specific settings for runtime, module format, and file extensions. This allows fine-grained control over the generated client. ```prisma generator client { provider = "prisma-client" output = "../generated/prisma" runtime = "nodejs" moduleFormat = "esm" generatedFileExtension = "ts" importFileExtension = "ts" } ``` -------------------------------- ### Run create-db CLI commands Source: https://github.com/prisma/skills/blob/main/prisma-postgres/references/create-db-cli.md Basic commands for provisioning databases and listing available regions. ```bash npx create-db@latest npx create-db@latest create [options] npx create-db@latest regions ``` -------------------------------- ### Open Studio on Custom Port Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/studio.md Launches the Studio interface on a specified port. ```bash prisma studio --port 3000 ``` -------------------------------- ### PrismaClient Basic Instantiation Source: https://github.com/prisma/skills/blob/main/prisma-client-api/references/constructor.md Demonstrates the basic way to instantiate PrismaClient with a driver adapter. ```APIDOC ## PrismaClient Basic Instantiation ### Description Instantiate PrismaClient with a driver adapter. ### Method `new PrismaClient(options)` ### Parameters #### Request Body - **adapter** (PrismaAdapter) - Required - Driver adapter instance. ### Request Example ```typescript import { PrismaClient } from '../generated/client' import { PrismaPg } from '@prisma/adapter-pg' const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }) const prisma = new PrismaClient({ adapter }) ``` ``` -------------------------------- ### Run Prisma Studio Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/studio.md Basic command to launch the Prisma Studio interface. ```bash prisma studio [options] ``` -------------------------------- ### Prisma CLI Quick Reference - Client Generation Source: https://context7.com/prisma/skills/llms.txt Generate or regenerate the Prisma Client. Use `--watch` to automatically regenerate the client when schema changes occur. ```bash # Client generation npx prisma generate npx prisma generate --watch ``` -------------------------------- ### Access CLI help documentation Source: https://github.com/prisma/skills/blob/main/prisma-postgres/references/create-db-cli.md Display help information for the CLI and its subcommands. ```bash npx create-db@latest --help npx create-db@latest create --help npx create-db@latest regions --help ``` -------------------------------- ### Legacy schema.prisma configuration Source: https://github.com/prisma/skills/blob/main/prisma-upgrade-v7/references/prisma-config.md Example of how datasource was defined in v6. ```prisma datasource db { provider = "postgresql" url = env("DATABASE_URL") directUrl = env("DIRECT_URL") } ``` -------------------------------- ### Start database in background Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/dev.md Runs the database instance in the background, freeing the terminal. ```bash prisma dev --detach ``` -------------------------------- ### Transition to migrations Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/db-push.md Creates a baseline migration from the current schema state. ```bash # Create baseline migration from current schema prisma migrate dev --name init ``` -------------------------------- ### Schema Change Example Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/migrate-dev.md Modifying the schema.prisma file to add a new field. ```prisma // schema.prisma - Add new field model User { id Int @id @default(autoincrement()) email String @unique name String? createdAt DateTime @default(now()) // New field } ``` -------------------------------- ### Configure database connection string Source: https://github.com/prisma/skills/blob/main/prisma-postgres-setup/SKILL.md Add the direct connection string to the .env file. ```text DATABASE_URL="" ``` -------------------------------- ### Drift Detection Prompt Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/migrate-dev.md Example output when the database schema is out of sync with the migration history. ```text Drift detected: Your database schema is not in sync. Do you want to reset your database? All data will be lost. ``` -------------------------------- ### Configure production database URL Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/migrate-deploy.md Example configuration for setting the datasource URL in prisma.config.ts. ```typescript import 'dotenv/config' import { defineConfig, env } from 'prisma/config' export default defineConfig({ datasource: { url: env('DATABASE_URL'), }, }) ``` -------------------------------- ### Run basic migration deployment Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/migrate-deploy.md The standard command to apply all pending migrations from the prisma/migrations directory. ```bash prisma migrate deploy ``` -------------------------------- ### Inspect data locally with Prisma Studio Source: https://github.com/prisma/skills/blob/main/prisma-postgres/references/console-and-connections.md Launches the local Prisma Studio interface for data inspection. ```bash npx prisma studio ``` -------------------------------- ### Create Project (with database) Source: https://github.com/prisma/skills/blob/main/prisma-postgres-setup/references/endpoints.md Creates a new project with an optional default database. The connection string for the created database can be extracted from the response. ```APIDOC ## Create project (with database) ### Description Creates a new project, optionally with a default database. The response contains the connection string for the created database. ### Method POST ### Endpoint /v1/projects ### Parameters #### Request Body - **name** (string) - Optional - Project display name. Auto-generated if not provided. - **region** (string) - Optional - The region for the database. Defaults to `us-east-1`. - **createDatabase** (boolean) - Optional - Whether to create a default database with the project. Defaults to `true`. ### Request Example ```json { "name": "my-project", "region": "us-east-1", "createDatabase": true } ``` ### Response #### Success Response (200) - **data** (object) - Contains details of the created project and its database. - **id** (string) - The unique identifier for the project. - **type** (string) - The type of the resource, always 'project'. - **url** (string) - The API URL for the project. - **name** (string) - The display name of the project. - **createdAt** (string) - The timestamp when the project was created. - **defaultRegion** (string) - The default region of the project. - **workspace** (object) - Information about the workspace the project belongs to. - **database** (object) - Information about the default database created with the project. - **id** (string) - The unique identifier for the database. - **type** (string) - The type of the resource, always 'database'. - **url** (string) - The API URL for the database. - **name** (string) - The name of the database. - **status** (string) - The status of the database (e.g., 'ready', 'provisioning'). - **createdAt** (string) - The timestamp when the database was created. - **isDefault** (boolean) - Indicates if this is the default database. - **defaultConnectionId** (string) - The ID of the default connection. - **connections** (array) - An array of connection objects. - **id** (string) - The unique identifier for the connection. - **type** (string) - The type of the resource, always 'connection'. - **url** (string) - The API URL for the connection. - **name** (string) - The name of the connection. - **createdAt** (string) - The timestamp when the connection was created. - **kind** (string) - The type of database (e.g., 'postgres'). - **endpoints** (object) - Connection endpoint details. - **direct** (object) - Direct connection endpoint. - **host** (string) - The database host. - **port** (integer) - The database port. - **connectionString** (string) - The direct connection string (use as DATABASE_URL). - **region** (object) - Information about the region where the database is hosted. ### Response Example ```json { "data": { "id": "proj_clx7abc123", "type": "project", "url": "https://api.prisma.io/v1/projects/proj_clx7abc123", "name": "my-project", "createdAt": "2025-06-15T10:30:00.000Z", "defaultRegion": "us-east-1", "workspace": { "id": "wksp_xyz789", "url": "https://api.prisma.io/v1/workspaces/wksp_xyz789", "name": "My Workspace" }, "database": { "id": "db_def456", "type": "database", "url": "https://api.prisma.io/v1/databases/db_def456", "name": "my-project", "status": "ready", "createdAt": "2025-06-15T10:30:00.000Z", "isDefault": true, "defaultConnectionId": "con_ghi789", "connections": [ { "id": "con_ghi789", "type": "connection", "url": "https://api.prisma.io/v1/connections/con_ghi789", "name": "Default", "createdAt": "2025-06-15T10:30:00.000Z", "kind": "postgres", "endpoints": { "direct": { "host": "db.prisma.io", "port": 5432, "connectionString": "postgres://user:pass@db.prisma.io:5432/postgres?sslmode=require" } } } ], "region": { "id": "us-east-1", "name": "US East (N. Virginia)" } } } } ``` ``` -------------------------------- ### Instantiate Prisma Client with MariaDB Adapter Source: https://github.com/prisma/skills/blob/main/prisma-database-setup/references/mysql.md Import and instantiate the `PrismaMariaDb` adapter, then pass it to the `PrismaClient` constructor. Ensure environment variables for database credentials are set. ```typescript import 'dotenv/config' import { PrismaClient } from '../generated/client' import { PrismaMariaDb } from '@prisma/adapter-mariadb' const adapter = new PrismaMariaDb({ host: 'localhost', port: 3306, connectionLimit: 5, user: process.env.MYSQL_USER, password: process.env.MYSQL_PASSWORD, database: process.env.MYSQL_DATABASE, }) const prisma = new PrismaClient({ adapter }) ``` -------------------------------- ### Instantiate Prisma Client Source: https://github.com/prisma/skills/blob/main/prisma-database-setup/references/prisma-client-setup.md Initialize the client with a database adapter. Ensure the import path matches your generator output. ```typescript import { PrismaClient } from '../generated/client' import { PrismaPg } from '@prisma/adapter-pg' const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }) const prisma = new PrismaClient({ adapter }) ``` -------------------------------- ### Prisma Output Path - Same Directory as Schema Source: https://github.com/prisma/skills/blob/main/prisma-upgrade-v7/references/schema-changes.md Example of configuring the output path to be in the same directory as the schema file. ```prisma output = "./generated/prisma" ``` -------------------------------- ### Validate schema in CI pipeline Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/validate.md Example configuration for running schema validation within a CI environment. ```yaml - name: Validate Schema run: npx prisma validate ``` -------------------------------- ### Rename Field to camelCase Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/db-pull.md Example of renaming a field from snake_case to camelCase in the Prisma schema using `@map`. ```prisma authorId Int? @map("author_id") ``` -------------------------------- ### Open Studio in Specific Browser Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/studio.md Launches the Studio interface using a specific browser application. ```bash prisma studio --browser firefox ``` -------------------------------- ### Rename Model to PascalCase Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/db-pull.md Example of renaming a model from snake_case to PascalCase in the Prisma schema using `@@map`. ```prisma model User { // Was: users @@map("users") } ``` -------------------------------- ### Apply migrations in CI/CD pipeline Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/migrate-deploy.md Example configuration for running migrations within a GitHub Actions workflow. ```yaml # GitHub Actions example - name: Apply migrations run: npx prisma migrate deploy env: DATABASE_URL: ${{ secrets.DATABASE_URL }} ``` -------------------------------- ### Bun Environment Variable Configuration Source: https://github.com/prisma/skills/blob/main/prisma-upgrade-v7/references/env-variables.md Bun handles .env files automatically, requiring no additional setup. ```typescript // prisma.config.ts (Bun) import { defineConfig, env } from 'prisma/config' export default defineConfig({ datasource: { url: env('DATABASE_URL'), }, }) ``` -------------------------------- ### Prisma CLI Quick Reference - Utilities Source: https://context7.com/prisma/skills/llms.txt Access utility commands such as opening the Prisma Studio GUI or displaying debug information. ```bash # Utilities npx prisma studio # Open database GUI npx prisma mcp # Start MCP server for AI tools npx prisma debug # Show debug information ``` -------------------------------- ### Configure prisma.config.ts Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/dev.md Configuration file setup to point the datasource URL to the local Prisma Postgres instance. ```typescript import 'dotenv/config' import { defineConfig, env } from 'prisma/config' export default defineConfig({ schema: 'prisma/schema.prisma', migrations: { path: 'prisma/migrations', }, datasource: { // Local Prisma Postgres URL (from prisma dev output) url: env('DATABASE_URL'), }, }) ``` -------------------------------- ### Run Prisma Generate and Migrate Source: https://github.com/prisma/skills/blob/main/prisma-upgrade-v7/SKILL.md Execute Prisma commands to generate the client and apply database migrations. Use 'prisma migrate dev' if schema changes require new migrations. ```bash npx prisma generate npx prisma migrate dev # if needed ``` -------------------------------- ### Get Database Source: https://github.com/prisma/skills/blob/main/prisma-postgres-setup/references/endpoints.md Retrieves details for a specific database, useful for checking its status after creation or for retrieving its configuration. ```APIDOC ## Get database ### Description Use to check database status after creation or to retrieve database details. ### Method GET ### Endpoint /v1/databases/{databaseId} ### Parameters #### Path Parameters - **databaseId** (string) - Required - The unique identifier of the database. ### Response #### Success Response (200) - **data** (object) - Contains details of the database. - **id** (string) - The unique identifier for the database. - **type** (string) - The type of the resource, always 'database'. - **url** (string) - The API URL for the database. - **name** (string) - The name of the database. - **status** (string) - The status of the database (e.g., 'ready'). - **createdAt** (string) - The timestamp when the database was created. - **isDefault** (boolean) - Indicates if this is the default database. - **defaultConnectionId** (string) - The ID of the default connection. - **connections** (array) - An array of connection objects. - **project** (object) - Information about the project the database belongs to. - **region** (object) - Information about the region where the database is hosted. ### Response Example ```json { "data": { "id": "db_def456", "type": "database", "url": "https://api.prisma.io/v1/databases/db_def456", "name": "my-project", "status": "ready", "createdAt": "2025-06-15T10:30:00.000Z", "isDefault": true, "defaultConnectionId": "con_ghi789", "connections": [], "project": { "id": "proj_clx7abc123", "url": "https://api.prisma.io/v1/projects/proj_clx7abc123", "name": "my-project" }, "region": { "id": "us-east-1", "name": "US East (N. Virginia)" } } } ``` ``` -------------------------------- ### Install Prisma 7 dependencies Source: https://github.com/prisma/skills/blob/main/prisma-postgres-setup/SKILL.md Required packages for Prisma 7, including the driver adapter and PostgreSQL driver. ```bash npm install prisma @prisma/client @prisma/adapter-pg pg dotenv ``` -------------------------------- ### Run migration and generation Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/generate.md Common workflow to migrate the database and refresh the client. ```bash prisma migrate dev --name my_migration prisma generate ``` -------------------------------- ### Instantiate Prisma Client with MSSQL Adapter Source: https://github.com/prisma/skills/blob/main/prisma-database-setup/references/sqlserver.md Import necessary modules, create a PrismaMssql adapter instance with your server details and credentials (using environment variables for sensitive information), and then instantiate PrismaClient with this adapter. ```typescript import 'dotenv/config' import { PrismaClient } from '../generated/client' import { PrismaMssql } from '@prisma/adapter-mssql' const adapter = new PrismaMssql({ server: 'localhost', port: 1433, database: 'mydb', user: process.env.SQLSERVER_USER, password: process.env.SQLSERVER_PASSWORD, options: { encrypt: true, trustServerCertificate: true, }, }) const prisma = new PrismaClient({ adapter }) ``` -------------------------------- ### Prisma Dev Configuration Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/dev.md Configure your `prisma.config.ts` to use the local Prisma Postgres database started with `prisma dev`. ```APIDOC ## Configuration Configure your `prisma.config.ts` to use local Prisma Postgres: ```typescript import 'dotenv/config' import { defineConfig, env } from 'prisma/config' export default defineConfig({ schema: 'prisma/schema.prisma', migrations: { path: 'prisma/migrations', }, datasource: { // Local Prisma Postgres URL (from prisma dev output) url: env('DATABASE_URL'), }, }) ``` ``` -------------------------------- ### Run Migrations with Accelerate Source: https://github.com/prisma/skills/blob/main/prisma-upgrade-v7/references/accelerate-users.md Execute Prisma CLI migration commands using the Accelerate URL. ```bash # Works with Accelerate URL prisma migrate deploy prisma db push ``` -------------------------------- ### Execute full push and generate workflow Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/db-push.md Combines schema synchronization with client generation. ```bash prisma db push prisma generate ``` -------------------------------- ### Add Relation Name for Clarity Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/db-pull.md Example of adding a descriptive relation name to improve clarity in the Prisma schema. ```prisma author User? @relation("PostAuthor", fields: [authorId], references: [id]) ``` -------------------------------- ### Create Full Management API SDK with OAuth Source: https://github.com/prisma/skills/blob/main/prisma-postgres/references/management-api-sdk.md Initialize the full SDK with OAuth support, including token storage and refresh capabilities. Requires client ID and redirect URI. ```typescript import { createManagementApiSdk, type TokenStorage } from '@prisma/management-api-sdk' const tokenStorage: TokenStorage = { async getTokens() { return null }, async setTokens(tokens) {}, async clearTokens() {}, } const api = createManagementApiSdk({ clientId: process.env.PRISMA_CLIENT_ID!, redirectUri: 'https://your-app.com/auth/callback', tokenStorage, }) ``` -------------------------------- ### Execute Prisma Format Command Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/format.md Run the formatting tool on the default schema file or a specified custom path. ```bash prisma format ``` ```bash prisma format --schema=./custom/schema.prisma ``` -------------------------------- ### Common Seed Commands Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/db-seed.md Examples of common commands to execute seed scripts using different Node.js runtimes. ```typescript // TypeScript with tsx seed: 'tsx prisma/seed.ts' ``` ```typescript // TypeScript with ts-node seed: 'ts-node prisma/seed.ts' ``` ```javascript // JavaScript seed: 'node prisma/seed.js' ``` -------------------------------- ### Distinct values on multiple fields Source: https://github.com/prisma/skills/blob/main/prisma-client-api/references/query-options.md Provide an array of field names to `distinct` to get unique combinations of those fields. ```typescript const locations = await prisma.user.findMany({ distinct: ['city', 'country'] }) ``` -------------------------------- ### Instantiate Prisma Client with Accelerate Source: https://github.com/prisma/skills/blob/main/prisma-upgrade-v7/references/accelerate-users.md Initialize the Prisma Client using the accelerateUrl property and the withAccelerate extension. ```typescript import { PrismaClient } from '../generated/client' import { withAccelerate } from '@prisma/extension-accelerate' // Use accelerateUrl instead of adapter export const prisma = new PrismaClient({ accelerateUrl: process.env.DATABASE_URL, }).$extends(withAccelerate()) ``` ```typescript import { PrismaClient } from '../generated/client' import { withAccelerate } from '@prisma/extension-accelerate' export const prisma = new PrismaClient({ accelerateUrl: process.env.DATABASE_URL, // prisma+postgres:// URL }).$extends(withAccelerate()) ``` ```typescript // Works in Vercel Edge, Cloudflare Workers, etc. import { PrismaClient } from '../generated/client' import { withAccelerate } from '@prisma/extension-accelerate' export const prisma = new PrismaClient({ accelerateUrl: process.env.DATABASE_URL, }).$extends(withAccelerate()) ``` -------------------------------- ### List database instances Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/dev.md Displays all local Prisma Postgres instances and their current status. ```bash prisma dev ls ``` -------------------------------- ### Select relation count Source: https://github.com/prisma/skills/blob/main/prisma-client-api/references/query-options.md Use `_count` within `select` to get the number of related records for a specific relation. ```typescript const users = await prisma.user.findMany({ select: { name: true, _count: { select: { posts: true } } } }) // Returns: { name: 'Alice', _count: { posts: 5 } } ``` -------------------------------- ### Instantiate Prisma Client Source: https://github.com/prisma/skills/blob/main/prisma-client-api/SKILL.md Initialize the Prisma Client with a database adapter. ```typescript import { PrismaClient } from '../generated/client' import { PrismaPg } from '@prisma/adapter-pg' const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }) const prisma = new PrismaClient({ adapter }) ``` -------------------------------- ### Add Documentation to Prisma Schema Source: https://github.com/prisma/skills/blob/main/prisma-cli/references/db-pull.md Example of adding JSDoc-style comments to models and fields in the Prisma schema for better documentation. ```prisma /// User account information model User { /// Primary email for authentication email String @unique } ```