From d3c5a8945bf9de3069fb366c257533ce63fc760d Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sun, 19 Apr 2026 20:47:49 +0200 Subject: [PATCH] feat(36-01): add scripts/grant-admin.ts for granting/revoking admin status --- scripts/grant-admin.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 scripts/grant-admin.ts diff --git a/scripts/grant-admin.ts b/scripts/grant-admin.ts new file mode 100644 index 0000000..7752890 --- /dev/null +++ b/scripts/grant-admin.ts @@ -0,0 +1,33 @@ +/** + * Grant or revoke admin status for a GearBox user. + * + * Usage: + * bun scripts/grant-admin.ts # grant admin + * bun scripts/grant-admin.ts --revoke # revoke admin + */ + +import { eq } from "drizzle-orm"; +import { db } from "../src/db/index.ts"; +import { users } from "../src/db/schema.ts"; + +const sub = process.argv[2]; +const revoke = process.argv.includes("--revoke"); + +if (!sub) { + console.error("Usage: bun scripts/grant-admin.ts [--revoke]"); + process.exit(1); +} + +const [user] = await db + .update(users) + .set({ isAdmin: !revoke }) + .where(eq(users.logtoSub, sub)) + .returning({ id: users.id, logtoSub: users.logtoSub, isAdmin: users.isAdmin }); + +if (!user) { + console.error(`User not found with logto_sub: ${sub}`); + process.exit(1); +} + +const action = revoke ? "Revoked admin from" : "Granted admin to"; +console.log(`${action} user ${user.id} (${user.logtoSub}) — isAdmin: ${user.isAdmin}`);