import { PrismaClient } from "@prisma/client";
import fs from "fs";
import path from "path";

const dbPath = "./prisma/dev.db";
if (fs.existsSync(dbPath)) {
  fs.unlinkSync(dbPath);
  console.log("Database deleted");
}

const prisma = new PrismaClient();

await prisma.$executeRawUnsafe(`
  CREATE TABLE "_prisma_migrations" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "checksum" TEXT NOT NULL,
    "finished_at" DATETIME,
    "execution_time" INTEGER NOT NULL,
    "migration_name" TEXT NOT NULL,
    "logs" TEXT,
    "rolled_back_at" DATETIME,
    "started_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "applied_steps_count" INTEGER NOT NULL DEFAULT 0
  )
`);

await prisma.$disconnect();
console.log("Database reset complete");
