Files
sass-mohfarawati/drizzle.config.ts
T
moh 26969e25b2 FIXED - Load .env in drizzle.config so drizzle-kit targets the right DB
- drizzle-kit does not read .env like the Next.js app, so DATABASE_URL was
  undefined and fell back to the default host, causing migrate to hang and
  push to fail against the wrong database
- Load .env via native process.loadEnvFile for local dev, guarded so
  production (env already set, no .env file) is unaffected
2026-09-20 02:05:54 +02:00

23 lines
705 B
TypeScript

import { existsSync } from "node:fs";
import { defineConfig } from "drizzle-kit";
// drizzle-kit (unlike the Next.js app) does not load .env automatically, so
// DATABASE_URL would be undefined and fall back to the wrong host. Load .env
// for local dev. In production the env is already provided (docker-compose)
// and no .env file exists, so this is skipped.
if (!process.env.DATABASE_URL && existsSync(".env")) {
process.loadEnvFile(".env");
}
export default defineConfig({
schema: "./lib/db/schema.ts",
out: "./lib/db/migrations",
dialect: "postgresql",
dbCredentials: {
url:
process.env.DATABASE_URL ??
"postgresql://postgres:postgres@localhost:5432/moh_sass",
},
});