sendou.ink/scripts/delete-badge.ts
2024-03-10 14:50:28 +02:00

29 lines
669 B
TypeScript

/* eslint-disable no-console */
import "dotenv/config";
import invariant from "tiny-invariant";
import { db } from "~/db/sql";
const rawId = process.argv[2]?.trim();
invariant(rawId, "id of badge is required (argument 1)");
const id = Number(rawId);
invariant(!Number.isNaN(id), "id must be a number");
async function main() {
const owners = await db
.selectFrom("BadgeOwner")
.select(["badgeId"])
.where("BadgeOwner.badgeId", "=", id)
.execute();
invariant(owners.length === 0, "Badge is still owned by someone");
await db.deleteFrom("Badge").where("id", "=", id).execute();
console.log("done with deleting the badge");
}
void main();