This commit is contained in:
2026-08-13 23:40:39 +02:00
parent 260fe28ac0
commit 322c70e5cf
4 changed files with 160 additions and 39 deletions
+2
View File
@@ -46,6 +46,8 @@ run([
adminPass,
"-name",
"Local Admin",
"-company",
"Local Admin Co",
"-confirm",
]);
+25 -10
View File
@@ -1,14 +1,13 @@
#!/usr/bin/env node
/**
* Upsert a platform admin (is_platform_admin + staff_role=admin).
* Loads monorepo-root `.env` only for DATABASE_URL (same as the API).
* Upsert a platform admin with a tenant company (fixes empty-company 400s).
* Loads monorepo-root `.env` only for DATABASE_URL.
* Email/password are CLI flags only — never read from .env.
*
* Usage (from repo root):
* npm run seed:platform-admin -- --email you@example.com --password '…'
* npm run seed:platform-admin -- --email you@example.com --promote-only
*
* Optional: --name "Display Name"
* npm run seed:platform-admin -- --email you@example.com --password '…' --company 'Acme Ops'
*/
import { spawnSync } from "node:child_process";
import path from "node:path";
@@ -22,22 +21,34 @@ function usage(msg) {
console.error(`Usage:
npm run seed:platform-admin -- --email you@example.com --password 'strong-password'
npm run seed:platform-admin -- --email you@example.com --promote-only
npm run seed:platform-admin -- --email you@example.com --password '…' --name 'Ops'
npm run seed:platform-admin -- --email you@example.com --password '…' --company 'Acme Ops'
Email/password must be passed on the CLI (not stored in .env).
DATABASE_URL comes from the shell or monorepo-root .env.`);
DATABASE_URL comes from the shell or monorepo-root .env.
Creates a company + admin membership + Free plan unless --no-company.`);
process.exit(1);
}
/** Parse `--key value` / `--flag` from argv after npm's `--`. */
function parseArgs(argv) {
const out = { email: "", password: "", name: "", promoteOnly: false };
const out = {
email: "",
password: "",
name: "",
company: "",
promoteOnly: false,
noCompany: false,
};
for (let i = 0; i < argv.length; i++) {
const a = argv[i];
if (a === "--promote-only") {
out.promoteOnly = true;
continue;
}
if (a === "--no-company") {
out.noCompany = true;
continue;
}
if (a === "--email" || a === "-email") {
out.email = String(argv[++i] || "").trim();
continue;
@@ -50,6 +61,10 @@ function parseArgs(argv) {
out.name = String(argv[++i] || "").trim();
continue;
}
if (a === "--company" || a === "-company") {
out.company = String(argv[++i] || "").trim();
continue;
}
if (a === "--help" || a === "-h") usage();
usage(`Unknown argument: ${a}`);
}
@@ -78,9 +93,9 @@ const args = [
opts.email,
"-confirm",
];
if (opts.name) {
args.push("-name", opts.name);
}
if (opts.name) args.push("-name", opts.name);
if (opts.company) args.push("-company", opts.company);
if (opts.noCompany) args.push("-no-company");
if (opts.promoteOnly) {
args.push("-promote-only");
} else {