From 14a4b1b4b4e752f5d620242752b1c9e251708264 Mon Sep 17 00:00:00 2001 From: miloschwartz Date: Mon, 19 Jan 2026 11:39:58 -0800 Subject: [PATCH] add clear license key command to pangctl --- cli/commands/clearLicenseKeys.ts | 36 ++++++++++++++++++++++++++++++++ cli/index.ts | 2 ++ 2 files changed, 38 insertions(+) create mode 100644 cli/commands/clearLicenseKeys.ts diff --git a/cli/commands/clearLicenseKeys.ts b/cli/commands/clearLicenseKeys.ts new file mode 100644 index 00000000..704641d3 --- /dev/null +++ b/cli/commands/clearLicenseKeys.ts @@ -0,0 +1,36 @@ +import { CommandModule } from "yargs"; +import { db, licenseKey } from "@server/db"; +import { eq } from "drizzle-orm"; + +type ClearLicenseKeysArgs = { }; + +export const clearLicenseKeys: CommandModule< + {}, + ClearLicenseKeysArgs +> = { + command: "clear-license-keys", + describe: + "Clear all license keys from the database", + // no args + builder: (yargs) => { + return yargs; + }, + handler: async (argv: {}) => { + try { + + console.log(`Clearing all license keys from the database`); + + // Delete all license keys + const deletedCount = await db + .delete(licenseKey) + .where(eq(licenseKey.licenseKeyId, licenseKey.licenseKeyId)) .returning();; // delete all + + console.log(`Deleted ${deletedCount.length} license key(s) from the database`); + + process.exit(0); + } catch (error) { + console.error("Error:", error); + process.exit(1); + } + } +}; diff --git a/cli/index.ts b/cli/index.ts index f44f41ba..328520aa 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -6,6 +6,7 @@ import { setAdminCredentials } from "@cli/commands/setAdminCredentials"; import { resetUserSecurityKeys } from "@cli/commands/resetUserSecurityKeys"; import { clearExitNodes } from "./commands/clearExitNodes"; import { rotateServerSecret } from "./commands/rotateServerSecret"; +import { clearLicenseKeys } from "./commands/clearLicenseKeys"; yargs(hideBin(process.argv)) .scriptName("pangctl") @@ -13,5 +14,6 @@ yargs(hideBin(process.argv)) .command(resetUserSecurityKeys) .command(clearExitNodes) .command(rotateServerSecret) + .command(clearLicenseKeys) .demandCommand() .help().argv;