updated db to work with the new user management functionality

updated db to work with the new user management functionality
This commit is contained in:
Kosztyk 2026-01-12 12:13:53 +02:00 committed by GitHub
parent c37def317e
commit 1896ebf469
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View file

@ -31,12 +31,25 @@ PRAGMA user_version = 1;`);
} }
const dbVersion = (db.query("PRAGMA user_version").get() as { user_version?: number }).user_version; const dbVersion = (db.query("PRAGMA user_version").get() as { user_version?: number }).user_version;
// existing migration: add status column to file_names
if (dbVersion === 0) { if (dbVersion === 0) {
db.exec("ALTER TABLE file_names ADD COLUMN status TEXT DEFAULT 'not started';"); db.exec("ALTER TABLE file_names ADD COLUMN status TEXT DEFAULT 'not started';");
db.exec("PRAGMA user_version = 1;"); db.exec("PRAGMA user_version = 1;");
console.log("Updated database to version 1."); console.log("Updated database to version 1.");
} }
/**
* Ensure `role` column exists on users table.
* This works for both fresh installs and existing DBs, without touching user_version.
*/
const userColumns = db.query("PRAGMA table_info(users)").all() as { name: string }[];
const hasRoleColumn = userColumns.some((col) => col.name === "role");
if (!hasRoleColumn) {
db.exec("ALTER TABLE users ADD COLUMN role TEXT NOT NULL DEFAULT 'user';");
console.log("Added 'role' column to users table.");
}
// enable WAL mode // enable WAL mode
db.exec("PRAGMA journal_mode = WAL;"); db.exec("PRAGMA journal_mode = WAL;");

View file

@ -20,4 +20,6 @@ export class User {
id!: number; id!: number;
email!: string; email!: string;
password!: string; password!: string;
role!: string; // 'admin' | 'user'
} }