sendou.ink/migrations/095-drop-unused-tournament-columns.js
Kalle 12590ba0df
Some checks failed
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled
Drop some unused columns, make TournamentRounds.maps always to be defined
2025-07-25 21:48:07 +03:00

36 lines
811 B
JavaScript

export function up(db) {
db.transaction(() => {
const roundsWithNullMaps = db
.prepare(
/* sql */ `select "id" from "TournamentRound" where "maps" is null`,
)
.all()
.map((row) => row.id);
for (const roundId of roundsWithNullMaps) {
const count = db
.prepare(
/* sql */ `select "bestOf" from "TournamentMatch" where "roundId" = @roundId`,
)
.get({ roundId }).bestOf;
db.prepare(
/* sql */ `update "TournamentRound" set "maps" = @maps where "id" = @id`,
).run({
id: roundId,
maps: JSON.stringify({
type: "BEST_OF",
count,
}),
});
}
db.prepare(
/* sql */ `alter table "TournamentMatch" drop column "bestOf"`,
).run();
db.prepare(
/* sql */ `alter table "CalendarEvent" drop column "avatarMetadata"`,
).run();
})();
}