Use ordered SQLite migrations (Refs #75)
CI / checks (push) Successful in 5m6s

This commit is contained in:
2026-10-10 00:01:18 -04:00
parent a0663e43b8
commit 8d1bb69591
56 changed files with 1085 additions and 736 deletions
+1 -6
View File
@@ -5,8 +5,6 @@ import { dirname, join, resolve } from 'node:path';
import { db } from '../db/index.js';
import { config } from '../config.js';
import { getHost, getHostOperation, listHosts, queueHostOperation } from '../hosts/index.js';
import { ensureGameFileSchema } from './schema.js';
import { ensureHostSchema } from '../hosts/schema.js';
import {
manifestChecksum,
receiveGameFile,
@@ -35,10 +33,7 @@ import type {
} from '../../game-files.js';
function database() {
const handle = db();
ensureGameFileSchema(handle);
ensureHostSchema(handle);
return handle;
return db();
}
export const gameFilesRoot = () =>
resolve(process.env.GAME_FILES_ROOT ?? join(dirname(config.dbPath), 'game-files'));
+1 -9
View File
@@ -1,13 +1,6 @@
import type Database from 'better-sqlite3';
const initialized = new WeakSet<Database.Database>();
export function ensureGameFileSchema(handle: Database.Database): void {
if (initialized.has(handle)) return;
// Worker readers open only after the controller has initialized the schema.
if (handle.readonly) {
initialized.add(handle);
return;
}
export function migrateGameFileSchema(handle: Database.Database): void {
handle.exec(`
CREATE TABLE IF NOT EXISTS game_file_libraries (
id TEXT PRIMARY KEY, name TEXT NOT NULL COLLATE NOCASE UNIQUE,
@@ -62,5 +55,4 @@ export function ensureGameFileSchema(handle: Database.Database): void {
handle.exec('ALTER TABLE host_library_caches ADD COLUMN bytes_verified INTEGER');
if (!cacheColumns.some((column) => column.name === 'transfer_progress'))
handle.exec('ALTER TABLE host_library_caches ADD COLUMN transfer_progress TEXT');
initialized.add(handle);
}