Add files via upload

This commit is contained in:
Kosztyk 2025-12-04 20:58:22 +02:00 committed by GitHub
parent 8ec2a22d73
commit 55fa5ae813
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;
// existing migration: add status column to file_names
if (dbVersion === 0) {
db.exec("ALTER TABLE file_names ADD COLUMN status TEXT DEFAULT 'not started';");
db.exec("PRAGMA user_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
db.exec("PRAGMA journal_mode = WAL;");

View file

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