diff --git a/server/scripts/__KT_DATABASE_MIGRATION/charts-chunithm.ts b/server/scripts/__KT_DATABASE_MIGRATION/charts-chunithm.ts new file mode 100644 index 000000000..4f63b2edd --- /dev/null +++ b/server/scripts/__KT_DATABASE_MIGRATION/charts-chunithm.ts @@ -0,0 +1,54 @@ +import { ChartDocument } from "kamaitachi-common"; +import db from "../../src/db/db"; +import CreateLogCtx from "../../src/logger"; +import MigrateRecords from "./migrate"; +import { gameOrders } from "kamaitachi-common/js/config"; + +const logger = CreateLogCtx("charts-chunithm.ts"); + +async function ConvertFn(c: any): Promise> { + let song = await db.songs.chunithm.findOne({ + id: c.id, + }); + + if (!song) { + logger.severe(`Cannot find song with ID ${c.id}?`); + throw new Error(`Cannot find song with ID ${c.id}?`); + } + + const newChartDoc: ChartDocument<"chunithm:Single"> = { + rgcID: null, + chartID: c.chartID, + difficulty: c.difficulty, + songID: c.id, + playtype: c.playtype, + levelNum: c.levelNum, + level: c.level.toString(), + flags: { + "IN BASE GAME": !!c.flags["IN BASE GAME"], + OMNIMIX: !!c.flags.OMNIMIX, + }, + data: { + inGameID: c.internals.inGameINTID, + }, + isPrimary: true, + versions: [], // sentinel + }; + + let idx = gameOrders.chunithm.indexOf(song.firstVersion!); + + if (idx === -1) { + logger.warn(`Invalid firstAppearance of ${song.firstVersion!}, running anyway.`); + newChartDoc.versions = [song.firstVersion!]; + } else { + newChartDoc.versions = gameOrders.chunithm.slice(idx); + } + + return newChartDoc; +} + +(async () => { + await MigrateRecords(db.charts.chunithm, "charts-chunithm", ConvertFn); + + process.exit(0); +})(); diff --git a/server/scripts/__KT_DATABASE_MIGRATION/songs-chunithm.ts b/server/scripts/__KT_DATABASE_MIGRATION/songs-chunithm.ts new file mode 100644 index 000000000..1420fc84a --- /dev/null +++ b/server/scripts/__KT_DATABASE_MIGRATION/songs-chunithm.ts @@ -0,0 +1,27 @@ +import { SongDocument } from "kamaitachi-common"; +import db from "../../src/db/db"; +import MigrateRecords from "./migrate"; + +function ConvertFn(c: any): SongDocument<"chunithm"> { + const newSongDoc: SongDocument<"chunithm"> = { + title: c.title, + artist: c.artist, + id: c.id, + firstVersion: c.firstAppearance, + "alt-titles": c["alt-titles"].filter((e: string) => e !== c.title), + "search-titles": c["search-titles"] + .map((e: string) => e.toString()) + .filter((e: string) => e !== c.title), + data: { + genre: c.genre, + }, + }; + + return newSongDoc; +} + +(async () => { + await MigrateRecords(db.songs.chunithm, "songs-chunithm", ConvertFn); + + process.exit(0); +})();