v3: added a roles/permissions system, added user management tab on user profile
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 42s

This commit is contained in:
khannurien
2026-06-28 06:21:23 +00:00
parent b567e390d9
commit 810faaf21a
22 changed files with 341 additions and 60 deletions

View File

@@ -0,0 +1,22 @@
import type { DatabaseSync } from "node:sqlite";
// Idempotent: safe to run against a fresh db (already created from schema.sql
// with the `role` column) or an existing one that predates it.
export function up(db: DatabaseSync): void {
const userCols = db.prepare(`PRAGMA table_info(users);`).all() as {
name: string;
}[];
if (!userCols.some((c) => c.name === "role")) {
db.exec(
`ALTER TABLE users ADD COLUMN role TEXT NOT NULL DEFAULT 'user';`,
);
}
// Backfill existing admins to role 'admin'. Guarded because the legacy
// is_admin column is absent on fresh databases (and dropped by 0005).
if (userCols.some((c) => c.name === "is_admin")) {
db.exec(
`UPDATE users SET role = 'admin' WHERE is_admin = 1 AND role != 'admin';`,
);
}
}

View File

@@ -0,0 +1,13 @@
import type { DatabaseSync } from "node:sqlite";
// Drops the legacy is_admin column now that `role` is the single source of
// truth. Idempotent: skips when the column is already gone (fresh databases
// created from schema.sql never had it). Must run after 0004 has backfilled.
export function up(db: DatabaseSync): void {
const userCols = db.prepare(`PRAGMA table_info(users);`).all() as {
name: string;
}[];
if (userCols.some((c) => c.name === "is_admin")) {
db.exec(`ALTER TABLE users DROP COLUMN is_admin;`);
}
}