import * as dotenv from "dotenv";
import type { Config } from "drizzle-kit";

dotenv.config({ path: ".env.local" });

const isProduction = process.env.VERCEL_ENV === "production";

export default {
  schema: "./src/app/db/schema/*",
  out: "./src/app/db/migrations",
  dialect: "postgresql",
  dbCredentials: {
    host: process.env.DB_HOST!,
    port: Number(process.env.DB_PORT!),
    user: process.env.DB_USERNAME!,
    password: process.env.DB_PASSWORD!,
    database: process.env.DB_NAME!,
    ssl: isProduction
      ? true // strict SSL for prod
      : { rejectUnauthorized: false }, // allow self-signed in dev/preview
  },
} satisfies Config;
