#!/usr/bin/env node
/**
 * Prisma CLI only auto-loads `.env`, not `.env.local` (Next.js does load .env.local).
 * This loads both so `npm run db:push` targets the same DATABASE_URL as `next dev`.
 */
import { config } from "dotenv";
import { spawnSync } from "node:child_process";
import path from "node:path";
import { fileURLToPath } from "node:url";

const root = path.join(path.dirname(fileURLToPath(import.meta.url)), "..");
config({ path: path.join(root, ".env") });
config({ path: path.join(root, ".env.local"), override: true });

const extra = process.argv.slice(2);
const r = spawnSync("npx", ["prisma", "db", "push", ...extra], {
  stdio: "inherit",
  cwd: root,
  env: process.env,
  shell: process.platform === "win32",
});
process.exit(r.status ?? 1);
