import { migrate } from "drizzle-orm/node-postgres/migrator";
import { db, pool } from "./index";

/**
 * Applies `drizzle/` to the database, then exits.
 *
 * `drizzle-kit` is a dev dependency and the runtime image prunes those, so the
 * deployment has no other way to reach its own schema. `drizzle-orm` ships this
 * migrator in production code and the SQL is already copied into the image.
 *
 * Only the worker runs it (see its command in compose.yaml): two services
 * migrating the same tables at the same boot would race.
 */
await migrate(db, { migrationsFolder: "./drizzle" });
await pool.end();
