import { config } from "dotenv";
import { migrate } from "drizzle-orm/postgres-js/migrator";
import postgres from "postgres";
import { drizzle } from "drizzle-orm/postgres-js";

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

const databaseUrl = process.env.DATABASE_URL ?? "";

if (!databaseUrl) {
  throw new Error("DATABASE_URL is required");
}

async function main() {
  const client = postgres(databaseUrl, { max: 1 });
  const database = drizzle(client);

  await migrate(database, { migrationsFolder: "drizzle" });
  await client.end();
}

main().catch((error) => {
  console.error(error);
  process.exit(1);
});
