This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import type Database from 'better-sqlite3';
|
||||
|
||||
/** Reporter identities and received sequences survive controller restarts with match history. */
|
||||
export function migrateLeaderboardReports(handle: Database.Database): void {
|
||||
const columns = new Set(
|
||||
(handle.prepare('PRAGMA table_info(leaderboard_matches)').all() as { name: string }[]).map(
|
||||
(column) => column.name
|
||||
)
|
||||
);
|
||||
for (const [name, definition] of [
|
||||
['reporter_match_key', 'TEXT'],
|
||||
['last_seq', 'INTEGER NOT NULL DEFAULT 0'],
|
||||
['report_count', 'INTEGER NOT NULL DEFAULT 0']
|
||||
]) {
|
||||
if (!columns.has(name))
|
||||
handle.exec(`ALTER TABLE leaderboard_matches ADD COLUMN ${name} ${definition}`);
|
||||
}
|
||||
handle.exec(`
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_leaderboard_reporter_match
|
||||
ON leaderboard_matches(server, reporter_match_key)
|
||||
WHERE reporter_match_key IS NOT NULL;
|
||||
CREATE TABLE IF NOT EXISTS leaderboard_match_reports (
|
||||
match_id INTEGER NOT NULL REFERENCES leaderboard_matches(id) ON DELETE CASCADE,
|
||||
seq INTEGER NOT NULL CHECK (typeof(seq) = 'integer' AND seq > 0),
|
||||
applied INTEGER NOT NULL CHECK (applied IN (0,1)),
|
||||
PRIMARY KEY (match_id, seq)
|
||||
);
|
||||
`);
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import { enableIncrementalVacuum, retentionClocks } from './retention-clocks.js'
|
||||
import { migrateHostSchema } from '../hosts/schema.js';
|
||||
import { migrateAuthSchema, migrateSuperViewerRole } from '../auth/schema.js';
|
||||
import { migrateGameFileSchema } from '../game-files/schema.js';
|
||||
import { migrateLeaderboardReports } from './leaderboard-reports.js';
|
||||
import type { Migration } from './migration-runner.js';
|
||||
|
||||
// Append only: never renumber entries or change an applied migration to add an
|
||||
@@ -97,6 +98,11 @@ export const migrations: readonly Migration[] = [
|
||||
name: 'super viewer authentication role',
|
||||
mode: 'foreign-keys-off',
|
||||
run: migrateSuperViewerRole
|
||||
},
|
||||
{
|
||||
version: 18,
|
||||
name: 'durable leaderboard report identity and sequences',
|
||||
run: migrateLeaderboardReports
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user