/**
 * Programmatic Drizzle migration runner.
 * Uses drizzle-orm/postgres-js/migrator instead of drizzle-kit CLI,
 * so drizzle-kit is not needed at runtime.
 */
import { drizzle } from "drizzle-orm/postgres-js";
import { migrate } from "drizzle-orm/postgres-js/migrator";
import postgres from "postgres";
import { resolve } from "path";

const sql = postgres(process.env.DATABASE_URL!, { max: 1 });
const db = drizzle(sql);

await migrate(db, {
  migrationsFolder: resolve(import.meta.dirname!, "../drizzle"),
});

console.log("Migrations applied.");
await sql.end();
