/**
 * Bundles src/db/migrate.ts into a single self-contained dist/migrate.mjs.
 *
 * Why: the Next.js standalone production image does NOT keep drizzle-orm or
 * postgres as separate node_modules packages (Next traces them straight into
 * server.js). The migration runner is a separate entrypoint, so it needs its
 * own bundle with those deps inlined. esbuild does exactly that.
 *
 * esbuild is already available as a transitive dependency of drizzle-kit/tsx,
 * so this adds no new package to the project.
 *
 * Run via: pnpm db:build-migrator   (invoked automatically inside the build).
 */
import { build } from "esbuild";

await build({
  entryPoints: ["src/db/migrate.ts"],
  bundle: true,                 // inline drizzle-orm + postgres into the output
  platform: "node",
  target: "node22",
  format: "esm",
  outfile: "dist/migrate.mjs",
  // postgres ships optional native bits; keep it bundled but let node resolve
  // built-ins normally. No externals — we want a fully standalone file.
  banner: {
    js: "// AUTO-GENERATED by scripts/build-migrator.mjs — do not edit.",
  },
});

console.log("[build-migrator] dist/migrate.mjs written.");
