Push for multi roles functionalities2

This commit is contained in:
Your Name 2026-07-02 10:07:05 +02:00
parent c05db56949
commit ed2af73145
2 changed files with 13 additions and 2 deletions

View File

@ -13,8 +13,18 @@ import { query } from '../db/connection';
async function main(): Promise<void> {
const adminRole = await query<{ id: number }[]>(`SELECT id FROM roles WHERE name = 'admin'`);
const superRole = await query<{ id: number }[]>(`SELECT id FROM roles WHERE name = 'super_admin'`);
if (!adminRole[0] || !superRole[0]) {
throw new Error('admin or super_admin role missing — run migrations first');
if (!adminRole[0]) {
throw new Error(
'Role "admin" not found. Ensure the database is initialized (at least one admin user should exist).'
);
}
if (!superRole[0]) {
throw new Error(
'Role "super_admin" not found. Run migrations first:\n' +
' From repo root: npm run db:migrate\n' +
' Then retry: npm run phase-b:grant-super-admin'
);
}
const result = await query<{ user_id: string }[]>(

View File

@ -22,6 +22,7 @@
"ssl:dns-init": "docker compose --profile dns-init run --rm -it certbot-dns-init",
"ssl:dns-renew": "docker compose --profile dns-renew run --rm -it certbot-dns-renew",
"db:migrate": "docker compose run --rm --no-deps --build backend node dist/db/migrate.js",
"migrate": "npm run db:migrate",
"phase-b:grant-super-admin": "docker compose run --rm --no-deps --build backend node dist/scripts/grantSuperAdminToAdmins.js",
"docker:local:grant-super-admin": "docker compose --env-file .env.docker run --rm --no-deps --build backend node dist/scripts/grantSuperAdminToAdmins.js"
}