From 26969e25b2d487d59e190fbb4d3e54e259a7b1ce Mon Sep 17 00:00:00 2001 From: moh Date: Sun, 20 Sep 2026 02:05:54 +0200 Subject: [PATCH] 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 --- drizzle.config.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drizzle.config.ts b/drizzle.config.ts index 497f9fa..eb7f59f 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -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",