Prisma Config reference
Overview
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 { defineConfig } from 'prisma/config'
export default defineConfig({
earlyAccess: true,
schema: {
kind: 'single',
filePath: './prisma/schema.prisma'
}
})
Or using TypeScript's satisfies
operator with the PrismaConfig
type:
import type { PrismaConfig } from 'prisma'
export default {
earlyAccess: true,
schema: {
kind: 'single',
filePath: './prisma/schema.prisma'
}
} satisfies PrismaConfig
Configuration interface
interface PrismaConfig {
// Required while in Early Access
earlyAccess: boolean
// Optional: Configure schema location (default: ./prisma/schema.prisma)
schema?: {
kind: 'single' | 'multi'
filePath?: string // Used when kind: 'single'
folderPath?: string // Used when kind: 'multi'
}
// Optional: Configure Prisma Studio database adapter
studio?: {
adapter?: (env: Env) => Promise<PrismaAdapter>
}
}
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.
schema
- Type:
object
- Required: No
- Default:
{ kind: 'single', filePath: './prisma/schema.prisma' }
Configures how Prisma locates and loads your schema file(s). See sub-options below for details.
schema.kind
- Type:
'single' | 'multi'
- Required: Only if
schema
is specified - Default:
'single'
Determines whether Prisma uses a single schema file or multiple files. Use 'single'
for a traditional single .prisma
file setup, or 'multi'
when using the prismaSchemaFolder
preview feature to split your schema across multiple files.
schema.filePath
- Type:
string
- Required: Only when
schema.kind
is'single'
- Default:
'./prisma/schema.prisma'
Specifies the path to your Prisma schema file when using a single-file setup.
schema.folderPath
- Type:
string
- Required: Only when
schema.kind
is'multi'
- Default: none
Specifies the path to the folder containing your Prisma schema files when using a multi-file setup.
studio
- Type:
object
- Required: No
- Default: none
Configures how Prisma Studio connects to your database.
studio.adapter
- Type:
(env: Env) => Promise<PrismaAdapter>
- 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 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:
- Install the dotenv package:
npm install dotenv
- 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
To use multiple schema files (requires prismaSchemaFolder
preview feature):
import path from 'node:path'
import type { PrismaConfig } from 'prisma'
export default {
earlyAccess: true,
schema: {
kind: 'multi',
folderPath: path.join('prisma', 'schema')
}
} satisfies PrismaConfig
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