handle series

This commit is contained in:
2026-05-17 15:37:00 -04:00
parent b7fb0b1043
commit 62c3deddaf
10 changed files with 346 additions and 81 deletions

View File

@@ -23,6 +23,17 @@ export function getDb(): Database.Database {
function initSchema(db: Database.Database): void {
db.exec(`
CREATE TABLE IF NOT EXISTS series (
id INTEGER PRIMARY KEY AUTOINCREMENT,
slug TEXT NOT NULL UNIQUE,
title TEXT NOT NULL,
library TEXT NOT NULL CHECK(library IN ('public','private')),
folder_path TEXT NOT NULL,
has_cover INTEGER NOT NULL DEFAULT 0,
last_scanned_at TEXT NOT NULL DEFAULT (datetime('now')),
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE TABLE IF NOT EXISTS games (
id INTEGER PRIMARY KEY AUTOINCREMENT,
slug TEXT NOT NULL UNIQUE,
@@ -66,4 +77,11 @@ function initSchema(db: Database.Database): void {
PRIMARY KEY (game_id, tag_id)
);
`);
const cols = db.prepare('PRAGMA table_info(games)').all() as Array<{ name: string }>;
if (!cols.some((c) => c.name === 'series_id')) {
db.exec(
'ALTER TABLE games ADD COLUMN series_id INTEGER REFERENCES series(id) ON DELETE SET NULL'
);
}
}