No matter what I try, npm run migrate defaults to my .env file. Npm run generate works just fine.

Hey, I am trying to set dynamic variable paths. When I run npm run migrate, it always defaults to my .env file and I can't find a way to change it. anyone have similar issues or know where I could go to fix this? example:

import { defineConfig } from "drizzle-kit";
import dotenv from "dotenv";
import path from "path";

// Load environment variables
const envFile =
  process.env.NODE_ENV === "production" ? ".env" : ".env.development";
const absolutePath = path.resolve(process.cwd(), envFile);



dotenv.config({ path: absolutePath });

const DB_URL = process.env.DATABASE_URL;

if (!DB_URL) {
  console.error("DATABASE_URL is not defined in the environment variables.");
  process.exit(1); // Terminate the application
}

/** @type { import("drizzle-kit").Config } */
export default defineConfig({
  dialect: "postgresql",
  schema: "./src/db/schema.ts",
  out: "./src/db/drizzle",
  dbCredentials: {
    url: DB_URL,
  },
});
Was this page helpful?