P
Prisma4w ago
Niels

How do I use the new prisma.config.ts file?

How do I use the new prisma.config.ts file?
2 Replies
Prisma AI Help
Skipping coffee for instant knowledge! Let's brew that AI answer now. Here’s a quick, source-backed guide to using prisma.config.ts. 1) Create the config file at the project root - Use either helper or types:
// Option A
import { defineConfig } from "prisma/config";
export default defineConfig({});

// Option B
import type { PrismaConfig } from "prisma";
export default {} satisfies PrismaConfig;
// Option A
import { defineConfig } from "prisma/config";
export default defineConfig({});

// Option B
import type { PrismaConfig } from "prisma";
export default {} satisfies PrismaConfig;
This file configures CLI commands like migrate, studio, etc. [Config reference] 2) Point to your schema (file or folder)
import path from "node:path";
import { defineConfig } from "prisma/config";

export default defineConfig({
// Single file
// schema: path.join("prisma", "schema.prisma"),

// Or multi-file schemas (folder)
schema: path.join("prisma", "schema"),
});
import path from "node:path";
import { defineConfig } from "prisma/config";

export default defineConfig({
// Single file
// schema: path.join("prisma", "schema.prisma"),

// Or multi-file schemas (folder)
schema: path.join("prisma", "schema"),
});
If using multi-file schemas, keep the migrations directory next to the .prisma file that defines the datasource. [Common patterns] 3) Load environment variables manually The CLI won’t auto-load .env when using prisma.config.ts. Install dotenv and import it:
import "dotenv/config";
import { defineConfig } from "prisma/config";

export default defineConfig({
schema: "prisma/schema.prisma",
});
import "dotenv/config";
import { defineConfig } from "prisma/config";

export default defineConfig({
schema: "prisma/schema.prisma",
});
[Common patterns; Issue note] 4) Optional: Configure migrations, views, typedSql, adapters
import path from "node:path";
import { defineConfig } from "prisma/config";

export default defineConfig({
schema: path.join("prisma", "schema.prisma"),
migrations: { path: path.join("prisma", "migrations") },
views: { path: path.join("db", "views") },
typedSql: { path: path.join("db", "queries") },
// experimental: { adapter: true },
// async adapter() { ... },
});
import path from "node:path";
import { defineConfig } from "prisma/config";

export default defineConfig({
schema: path.join("prisma", "schema.prisma"),
migrations: { path: path.join("prisma", "migrations") },
views: { path: path.join("db", "views") },
typedSql: { path: path.join("db", "queries") },
// experimental: { adapter: true },
// async adapter() { ... },
});
[Config reference] 5) Path resolution rules - Paths in the config are resolved relative to the config file’s location. - With pnpm, the CLI auto-detects the config from root or subdirs. - With npm exec/bun, run from project root or pass --config.
npm exec prisma -- --config ./prisma.config.ts validate
npm exec prisma -- --config ./prisma.config.ts validate
[Path resolution] 6) Multi-file schema gotchas - Set schema to the folder (e.g., prisma or prisma/schema), not just a subfolder missing schema.prisma. - Place prisma.config.ts at project root. [GitHub issue 27974; Common patterns] Tip: If you previously used package.json "prisma.schema", prisma.config.ts replaces that centralization with more power and structure. [Discussion]
Nurul
Nurul4w ago
Was the bot response helpful? Please let me know if there are any improvements you would like to see on our bot 🙂

Did you find this page helpful?