mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-03 12:28:13 +03:00
create scripts to migrate folders and support spread
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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[] {
|
||||
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} +`, "gi"), "");
|
||||
|
||||
logger.info(`Porting folder ${fd.title} (${playtype})`);
|
||||
|
||||
docs.push(fd);
|
||||
}
|
||||
|
||||
return docs;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await MigrateRecords(db.folders, "folders", ConvertFn);
|
||||
|
||||
process.exit(0);
|
||||
})();
|
||||
@@ -42,7 +42,7 @@ export default async function MigrateRecords(
|
||||
});
|
||||
|
||||
logger.info(`Inserting ${newDocuments.length} documents.`);
|
||||
await existingCollection.insert(newDocuments);
|
||||
await existingCollection.insert(newDocuments.flat());
|
||||
logger.info(`Done!`);
|
||||
|
||||
process.exit(0);
|
||||
|
||||
Reference in New Issue
Block a user