Add files via upload
This commit is contained in:
parent
8ec2a22d73
commit
55fa5ae813
2 changed files with 15 additions and 0 deletions
13
src/db/db.ts
13
src/db/db.ts
|
|
@ -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;");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,4 +20,6 @@ export class User {
|
||||||
id!: number;
|
id!: number;
|
||||||
email!: string;
|
email!: string;
|
||||||
password!: string;
|
password!: string;
|
||||||
|
role!: string; // 'admin' | 'user'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue