Files
zkldi_Tachi/server/scripts/__KT_DATABASE_MIGRATION/folders.ts
T
2021-05-10 04:50:58 +01:00

49 lines
1.3 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
import { FolderDocument, Game } from "kamaitachi-common";
import { validPlaytypes, gameHuman } from "kamaitachi-common/js/config";
import db from "../../src/db/db";
import CreateLogCtx from "../../src/logger";
import MigrateRecords from "./migrate";
import crypto from "crypto";
const logger = CreateLogCtx("folders.ts");
function ConvertFn(c: any): FolderDocument[] {
throw new Error("This doesn't work, It was migrated elsewhere.");
let docs = [];
for (const playtype of validPlaytypes[c.game as Game]) {
const fd: FolderDocument = {
title: c.title,
game: c.game,
playtype,
type: "query" as const,
query: {
collection: c.query.collection,
body: c.query.query,
},
folderID: crypto.randomBytes(20).toString("hex"),
table: c.table,
tableIndex: 0, // ???
};
let gh = gameHuman[c.game as Game];
fd.title = fd.title.replace(new RegExp(`${gh} +`, "giu"), "");
logger.info(`Porting folder ${fd.title} (${playtype})`);
docs.push(fd);
}
return docs;
}
(async () => {
await MigrateRecords(db.folders, "folders", ConvertFn);
process.exit(0);
})();