Overview
Theprisma.config.ts file is the central configuration file for your Prisma project. It replaces the datasource URLs and other configuration previously stored in schema.prisma, providing a type-safe, programmatic way to configure Prisma.
File Location
By default, Prisma looks forprisma.config.ts in the following locations:
./prisma.config.ts(project root)./.config/prisma.ts
--config flag with CLI commands.
Supported File Extensions
Prisma supports the following configuration file formats:.ts- TypeScript.js- JavaScript.mjs- ES Module.cjs- CommonJS.mts- TypeScript ES Module.cts- TypeScript CommonJS
Basic Structure
While you can export a plain object without using
defineConfig, using the function provides better type safety and validation.Configuration Options
datasource
Defines the database connection configuration.The database connection URL. Required for migration and introspection commands.
The shadow database URL used during migrations for diffing. Optional.
schema
Specifies the path to your Prisma schema file or directory.Path to a single
.prisma file or a directory containing multiple .prisma files.Paths can be absolute or relative. Relative paths are resolved from the config file location.
migrations
Configures Prisma Migrate behavior.Directory where migration files are stored and looked up.
Command to run for database seeding after migrations are applied.Examples:
- TypeScript:
'tsx prisma/seed.ts' - Node.js:
'node prisma/seed.js' - Shell script:
'./prisma/seed.sh'
SQL script to set up external tables and enums during migration diffing. Requires
experimental.externalTables to be enabled.tables
Configures external table management.List of tables that are externally managed. Prisma will not generate migrations for these tables but will include them in the schema and client API. Requires You can specify schema-qualified table names:
experimental.externalTables to be enabled.'schema_name.table_name'enums
Configures external enum management.List of enums that are externally managed. Prisma will not generate migrations for these enums but will include them in the schema and client API. Requires
experimental.externalTables to be enabled.views
Configures database views.Directory containing view definition SQL files (
*.sql).typedSql
Configures the TypedSQL feature.Directory containing TypedSQL query files (
*.sql).experimental
Enables experimental features.Enables support for external tables and enums. Required when using
tables.external, enums.external, or migrations.initShadowDb.Enables support for Prisma extensions configuration in the config file. Required when using the
extensions option.Complete Example
Path Resolution
Relative Paths
Relative paths in the configuration are resolved from the directory containing the config file:Absolute Paths
You can use absolute paths or Node.js path utilities:Validation
Prisma validates your configuration at load time:- Type Safety: When using TypeScript, configuration errors are caught at authoring time
- Runtime Validation: Invalid configurations throw errors with clear messages
- Experimental Features: Features requiring experimental flags will throw errors if the flag is not enabled
Common Validation Errors
Type Safety
For better type checking without usingdefineConfig, you can use the satisfies operator:
CLI Integration
All Prisma CLI commands support the--config flag to specify a custom config location:
--config flag is provided, Prisma searches for the config file in default locations.