Skip to main content

Prisma Config reference

Overview

warning

The Prisma Config file 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 either of 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"),
    migrations: {
    path: path.join("db", "migrations"),
    },
    views: {
    path: path.join("db", "views"),
    },
    typedSql: {
    path: path.join("db", "queries"),
    }
    });
  • 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("db", "schema.prisma"),
    migrations: {
    path: path.join("db", "migrations"),
    },
    views: {
    path: path.join("db", "views"),
    },
    typedSql: {
    path: path.join("db", "queries"),
    }
    } satisfies PrismaConfig;

Configuration interface

Here is a simplified version of the PrismaConfig type:

export declare type PrismaConfig = {
// 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 Driver Adapter used for Prisma CLI.
adapter?: () => Promise<SqlMigrationAwareDriverAdapterFactory>;

// The configuration for Prisma Studio.
studio?: {
adapter: () => Promise<SqlMigrationAwareDriverAdapterFactory>;
};

// Configuration for Prisma migrations.
migrations?: {
path: string;
};

// Configuration for the database view entities.
views?: {
path: string;
};

// Configuration for the `typedSql` preview feature.
typedSql?: {
path: string;
};
};

Options reference

earlyAccess

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

PropertyTypeRequiredDefault
earlyAccessbooleanYes (during Early Access)none

schema

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.

PropertyTypeRequiredDefault
schemastringNo./prisma/schema.prisma and ./schema.prisma

migrate

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

PropertyTypeRequiredDefault
migrateobjectNo{}

migrate.adapter

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.

PropertyTypeRequiredDefault
migrate.adapter(env: Env) => Promise<SqlMigrationAwareDriverAdapterFactory>Nonone

Example using the Prisma ORM D1 driver adapter:

import path from "node:path";
import type { PrismaConfig } from "prisma";
import { PrismaD1 } 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 PrismaD1({
CLOUDFLARE_D1_TOKEN: env.CLOUDFLARE_D1_TOKEN,
CLOUDFLARE_ACCOUNT_ID: env.CLOUDFLARE_ACCOUNT_ID,
CLOUDFLARE_DATABASE_ID: env.CLOUDFLARE_DATABASE_ID,
});
},
},
} satisfies PrismaConfig<Env>;

Note: As of Prisma ORM v6.11.0, the D1 adapter has been renamed from PrismaD1HTTP to PrismaD1.

studio

Configures how Prisma Studio connects to your database. See sub-options below for details.

PropertyTypeRequiredDefault
studioobjectNonone

studio.adapter

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.

PropertyTypeRequiredDefault
studio.adapter (env: Env) => Promise<SqlMigrationAwareDriverAdapterFactory>Nonone

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;

migrations.path

The path to the directory where Prisma should store migration files, and look for them.

PropertyTypeRequiredDefault
migrations.pathstringNonone

views.path

The path to the directory where Prisma should look for the SQL view definitions.

PropertyTypeRequiredDefault
views.pathstringNonone

typedSql.path

The path to the directory where Prisma should look for the SQL files used for generating typings via typedSql.

PropertyTypeRequiredDefault
typedSql.pathstringNonone

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