Add a 2dxtra migration script, and revert tachi-common.

This commit is contained in:
zkldi
2021-09-27 23:32:06 +01:00
parent d8720d8380
commit 80c47db769
3 changed files with 73 additions and 2 deletions
+1 -1
View File
@@ -74,7 +74,7 @@
"redis": "3.1.2",
"rimraf": "3.0.2",
"safe-json-stringify": "1.2.0",
"tachi-common": "0.2.25",
"tachi-common": "0.2.19",
"typescript": "4.3.4",
"winston": "3.3.3",
"winston-transport": "^4.4.0"
+1 -1
View File
@@ -4,7 +4,7 @@ import { ChartDocument, IDStrings } from "tachi-common";
import { Random20Hex } from "utils/misc";
export async function QuickInsert<I extends IDStrings>(
base: ChartDocument<I>,
base: Omit<ChartDocument<I>, "chartID">,
content: Partial<ChartDocument<I>>[],
coll: ICollection
) {
@@ -0,0 +1,71 @@
/* eslint-disable no-await-in-loop */
import db from "external/mongo/db";
import { rootLogger } from "lib/logger/logger";
import { ChartDocument, Difficulties } from "tachi-common";
import { FindIIDXChartOnInGameID } from "utils/queries/charts";
async function ConvertChart(chart: ChartDocument<"iidx:SP" | "iidx:DP">) {
// We need to get the related official song. The best way to do this is
// probably with song IDs.
const originalChart = await FindIIDXChartOnInGameID(
chart.data.inGameID,
chart.playtype,
chart.difficulty
);
if (!originalChart) {
rootLogger.error(`Can't find original chart.`, { chart });
throw new Error(`Can't find original chart.`);
}
return {
difficulty: `${chart.data["2dxtraSet"]!} ${chart.difficulty}` as Difficulties[
| "iidx:SP"
| "iidx:DP"],
songID: originalChart!.songID,
};
}
if (require.main === module) {
(async () => {
const modCharts = (await db.charts.iidx.find({
"data.2dxtraSet": { $ne: null },
difficulty: { $in: ["BEGINNER", "NORMAL", "HYPER", "ANOTHER", "LEGGENDARIA"] },
})) as ChartDocument<"iidx:SP" | "iidx:DP">[];
rootLogger.info(`Modifying ${modCharts.length} charts.`);
for (const chart of modCharts) {
const setDoc = await ConvertChart(chart);
await db.charts.iidx.update(
{
chartID: chart.chartID,
},
{ $set: setDoc }
);
// We're also going to have to port over old scores.
await db.scores.update(
{
chartID: chart.chartID,
},
{
$set: {
songID: setDoc.songID,
},
}
);
}
rootLogger.info(`Removing ${modCharts.length} songs.`);
await db.songs.iidx.remove({
songID: { $in: modCharts.map((e) => e.songID) },
});
rootLogger.info(`Done.`);
})();
}