Prisma Configuration

The central nervous system of your ORM. In Prisma v7+, prisma.config.ts replaces legacy configuration methods, offering full TypeScript support and programmatic control.

The Configuration Hub

Create a file named prisma.config.ts in your project root.

prisma.config.ts
import { defineConfig, env } from "prisma/config";
import "dotenv/config";

export default defineConfig({
  // 1. Schema Location
  schema: "prisma/schema.prisma",

  // 2. Migration & Seeding Strategy
  migrations: {
    path: "prisma/migrations",
    seed: "tsx prisma/seed.ts",
  },

  // 3. Database Connection
  datasource: {
    url: env("DATABASE_URL"),
  },
});

Configuration API

Property Type Description
schema string Path to your schema.prisma file.
migrations object Configures the output directory for SQL migrations and the command used to seed the database.
datasource object Defines connection details. Supports url and shadowDatabaseUrl.

Environment Variables

Prisma v7 does not auto-load .env. You must explicitly import a loader.

import "dotenv/config";

Type Safety

Use the env() helper to ensure type-safe access to your environment strings.

url: env("DATABASE_URL")

# Shadow Database

Required for MySQL providers to detect schema drift accurately.

Why is this required?

Prisma Migrate creates a temporary "shadow" database to test your schema changes before applying them. Since MySQL does not support DDL transactions (rollback on error), this shadow DB ensures your main database doesn't get corrupted if a migration fails halfway.

Implementation

prisma.config.ts
export default defineConfig({
  // ... other options
  datasource: {
    url: env("DATABASE_URL"),
    // Add the shadow database URL here
    shadowDatabaseUrl: env("SHADOW_DATABASE_URL"),
  },
});
# .env file
SHADOW_DATABASE_URL="mysql://user:pass@localhost:3306/my_app_shadow"