sendou.ink/migrations/136-fix-empty-placements-progression.js
Kalle 2d3bff6437 Fix tournament page crash on page load + add backend check against it
Error: Invariant failed: Empty placements not supported
I don't think it's possible for this to happen normally
but this fix provides more defense just in case
2026-05-01 15:30:01 +03:00

20 lines
516 B
JavaScript

const TOURNAMENT_ID = 1078;
export function up(db) {
const row = db
.prepare(/* sql */ `select "settings" from "Tournament" where "id" = ?`)
.get(TOURNAMENT_ID);
if (!row) return;
const settings = JSON.parse(row.settings);
const source = settings.bracketProgression?.[1]?.sources?.[0];
if (!source || source.placements?.length !== 0) return;
source.placements = [-1];
db.prepare(
/* sql */ `update "Tournament" set "settings" = ? where "id" = ?`,
).run(JSON.stringify(settings), TOURNAMENT_ID);
}