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
This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
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",
|
||||
|
||||
Reference in New Issue
Block a user