From bcd014c352806d3e25382fe8722ad35c302daf9a Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sun, 15 Jun 2025 21:24:56 +0300 Subject: [PATCH] Nuke season script Closes #2396 --- scripts/nuke-season-data.ts | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 scripts/nuke-season-data.ts diff --git a/scripts/nuke-season-data.ts b/scripts/nuke-season-data.ts new file mode 100644 index 000000000..aefb0546c --- /dev/null +++ b/scripts/nuke-season-data.ts @@ -0,0 +1,45 @@ +import "dotenv/config"; +import { db } from "~/db/sql"; +import * as Seasons from "~/features/mmr/core/Seasons"; +import { addDummySkill } from "~/features/sendouq-match/queries/addDummySkill.server"; +import { dateToDatabaseTimestamp } from "~/utils/dates"; +import { logger } from "~/utils/logger"; + +async function main() { + if (Seasons.current()) { + throw new Error("There is a current season"); + } + + if (Seasons.next()?.nth !== 8) { + throw new Error("Next season is not 8. Script needs modifying"); + } + + const wrongSeasonStartDate = new Date("2025-06-14T18:00:00.000Z"); + + const allMatches = await db + .selectFrom("GroupMatch") + .selectAll() + .where( + "GroupMatch.createdAt", + ">=", + dateToDatabaseTimestamp(wrongSeasonStartDate), + ) + .execute(); + + await db + .deleteFrom("Skill") + .where( + "Skill.groupMatchId", + "in", + allMatches.map((m) => m.id), + ) + .execute(); + + for (const match of allMatches) { + addDummySkill(match.id); + } + + logger.info(`All done with nuking the season (${allMatches.length} matches)`); +} + +void main();