Skip to main content

Prisma Config reference

Overview

warning

This feature is currently in Early Access and still subject to change.

The prisma.config.ts file configures the Prisma CLI, including subcommands like migrate and studio, using TypeScript. You can define your config in two ways:

Using the defineConfig helper:

import path from 'node:path';
import { defineConfig } from 'prisma/config';

export default defineConfig({
earlyAccess: true,
schema: path.join('prisma', 'schema.prisma'),
});

Or using TypeScript's satisfies operator with the PrismaConfig type:

import path from 'node:path';
import type { PrismaConfig } from 'prisma'

export default {
earlyAccess: true,
schema: path.join('prisma', 'schema.prisma'),
} satisfies PrismaConfig

Configuration interface

export declare type PrismaConfig<Env extends EnvVars = never> = {
/**
* Whether features with an unstable API are enabled.
*/
earlyAccess: true;
/**
* The path to the schema file or path to a folder that shall be recursively searched for .prisma files.
*/
schema?: string;
/**
* The configuration for Prisma Studio.
*/
studio?: PrismaStudioConfigShape<Env>;
/**
* The configuration for Prisma Migrate + Introspect
*/
migrate?: PrismaMigrateConfigShape<Env>;
};

Options reference

earlyAccess

  • Type: boolean
  • Required: Yes (during Early Access)
  • Default: none

Controls whether the config file is enabled. Must be set to true during Early Access.

migrate

  • Type: object
  • Required: No
  • Default: {}

Configures how Prisma Migrate communicates with your underlying database. See sub-options below for details.

migrate.adapter

  • Type: (env: Env) => Promise<SqlMigrationAwareDriverAdapterFactory>
  • Required: No
  • Default: none

A function that returns a Prisma driver adapter instance which is used by the Prisma CLI to run migrations. The function receives an env parameter containing environment variables and should return a Promise that resolves to a valid Prisma driver adapter.

Example using the Prisma ORM D1 driver adapter:

import path from 'node:path'
import type { PrismaConfig } from 'prisma'
import { PrismaD1HTTP } from '@prisma/adapter-d1'

// import your .env file
import 'dotenv/config'

type Env = {
CLOUDFLARE_D1_TOKEN: string
CLOUDFLARE_ACCOUNT_ID: string
CLOUDFLARE_DATABASE_ID: string
}

export default {
earlyAccess: true,
schema: path.join('prisma', 'schema.prisma'),

migrate: {
async adapter(env) {
return new PrismaD1HTTP({
CLOUDFLARE_D1_TOKEN: env.CLOUDFLARE_D1_TOKEN,
CLOUDFLARE_ACCOUNT_ID: env.CLOUDFLARE_ACCOUNT_ID,
CLOUDFLARE_DATABASE_ID: env.CLOUDFLARE_DATABASE_ID,
})
},
},
} satisfies PrismaConfig<Env>

schema

  • Type: string
  • Required: No
  • Default: ./prisma/schema.prisma and ./schema.prisma

Configures how Prisma ORM locates and loads your schema file(s). Can be a file or folder path. Relative paths are resolved relative to the prisma.config.ts file location. See here for more info about schema location options.

studio

  • Type: object
  • Required: No
  • Default: none

Configures how Prisma Studio connects to your database.

studio.adapter

  • Type: (env: Env) => Promise<SqlMigrationAwareDriverAdapterFactory>
  • Required: No
  • Default: none

A function that returns a Prisma driver adapter instance. The function receives an env parameter containing environment variables and should return a Promise that resolves to a valid Prisma driver adapter.

Example using the Prisma ORM LibSQL driver adapter:

import type { PrismaConfig } from 'prisma'

export default {
earlyAccess: true,
studio: {
adapter: async (env: Env) => {
const { PrismaLibSQL } = await import('@prisma/adapter-libsql')
const { createClient } = await import('@libsql/client')

const libsql = createClient({
url: env.DOTENV_PRISMA_STUDIO_LIBSQL_DATABASE_URL,
})
return new PrismaLibSQL(libsql)
},
},
} satisfies PrismaConfig

Common patterns

Setting up your project

To get started with Prisma Config, create a prisma.config.ts file in your project root. You can use either of these approaches:

Using defineConfig:

import { defineConfig } from 'prisma/config'

export default defineConfig({
earlyAccess: true
})

Using TypeScript types:

import type { PrismaConfig } from 'prisma'

export default {
earlyAccess: true
} satisfies PrismaConfig

Using environment variables

When using prisma.config.ts, environment variables from .env files are not automatically loaded. You'll need to:

  1. Install the dotenv package:
npm install dotenv
  1. Import dotenv/config in your config file:
import 'dotenv/config'
import type { PrismaConfig } from 'prisma'

export default {
earlyAccess: true,
// now you can use process.env variables
} satisfies PrismaConfig

Using multi-file schemas

If you want to split your Prisma schema into multiple files, you need to use the prismaSchemaFolder Preview feature and specify the path to your Prisma schema folder via the schema property:

import path from 'node:path';
import type { PrismaConfig } from 'prisma'

export default {
earlyAccess: true,
schema: path.join('prisma', 'schema'),
} satisfies PrismaConfig

In that case, your migrations directory must be located next to the .prisma file that defines the datasource block.

For example, assuming schema.prisma defines the datasource, here's how how need to place the migrations folder:

# `migrations` and `schema.prisma` are on the same level
.
├── migrations
├── models
│ ├── posts.prisma
│ └── users.prisma
└── schema.prisma

Custom config location

You can specify a custom location for your config file when running Prisma CLI commands:

prisma validate --config ./path/to/myconfig.ts