require("dotenv").config();
const mongoose = require("mongoose");

async function run() {
  try {
    await mongoose.connect(process.env.MONGODB_URI);

    console.log("Connected DB");

    const collections = await mongoose.connection.db
      .listCollections({ name: "auditlogs" })
      .toArray();

    if (collections.length > 0) {
      console.log("AuditLog collection already exists");
      process.exit(0);
    }

    await mongoose.connection.createCollection("auditlogs");
    console.log("AuditLog collection created");

    process.exit(0);
  } catch (err) {
    console.error(err);
    process.exit(1);
  }
}

run();
