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",