-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdrizzle.config.ts
More file actions
41 lines (37 loc) · 1.07 KB
/
Copy pathdrizzle.config.ts
File metadata and controls
41 lines (37 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { readFileSync, existsSync } from "fs";
import { defineConfig } from "drizzle-kit";
// drizzle-kit doesn't auto-load .env.local — load it manually
const envPath = ".env.local";
if (existsSync(envPath)) {
for (const line of readFileSync(envPath, "utf8").split("\n")) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith("#")) continue;
const eq = trimmed.indexOf("=");
if (eq > 0) {
const key = trimmed.slice(0, eq).trim();
if (!process.env[key]) process.env[key] = trimmed.slice(eq + 1).trim();
}
}
}
const pushUrl =
process.env.DATABASE_MIGRATION_URL ??
process.env.DATABASE_SERVICE_ROLE_URL ??
process.env.DATABASE_URL;
if (!pushUrl) {
throw new Error(
"DATABASE_MIGRATION_URL (or DATABASE_SERVICE_ROLE_URL / DATABASE_URL) is required for drizzle-kit",
);
}
export default defineConfig({
out: "./drizzle",
schema: ["./lib/db/schema.ts"],
dialect: "postgresql",
schemaFilter: ["public"],
migrations: {
schema: "drizzle",
table: "__drizzle_migrations",
},
dbCredentials: {
url: pushUrl,
},
});