1
0

fix: loan error surfacing, non-admin export, guarded atomic migration, expanded player controls

This commit is contained in:
2026-09-03 23:50:54 +02:00
parent 9b2bc22d59
commit 3edf7574f9
7 changed files with 99 additions and 35 deletions

View File

@@ -95,18 +95,24 @@ function setSchemaVersion(db: DB, version: number): void {
export function migrateUpgrades(db: DB): void {
const version = getSchemaVersion(db)
if (version < 2) {
db.exec(`
ALTER TABLE digital_albums ADD COLUMN last_played_at TEXT;
CREATE TABLE IF NOT EXISTS loans (
const hasColumn = (db.prepare('PRAGMA table_info(digital_albums)').all() as { name: string }[]).some(
(c) => c.name === 'last_played_at'
)
const apply = db.transaction(() => {
if (!hasColumn) {
db.exec('ALTER TABLE digital_albums ADD COLUMN last_played_at TEXT')
}
db.exec(`CREATE TABLE IF NOT EXISTS loans (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
item_id INTEGER NOT NULL REFERENCES collection_items(id) ON DELETE CASCADE,
borrower TEXT NOT NULL,
lent_at TEXT NOT NULL DEFAULT (datetime('now')),
returned_at TEXT
);
`)
setSchemaVersion(db, 2)
);`)
setSchemaVersion(db, 2)
})
apply()
}
}