diff --git a/server/scripts/set-indexes.ts b/server/scripts/set-indexes.ts index ddb324787..67484e99a 100644 --- a/server/scripts/set-indexes.ts +++ b/server/scripts/set-indexes.ts @@ -2,7 +2,7 @@ import monk from "monk"; import { Command } from "commander"; import CreateLogCtx from "../src/logger"; import { IndexOptions } from "mongodb"; -import { ValidDatabases, Game } from "kamaitachi-common"; +import { Databases, ValidDatabases } from "kamaitachi-common"; import { supportedGames } from "kamaitachi-common/js/config"; const logger = CreateLogCtx("set-indexes.ts"); @@ -31,7 +31,7 @@ function index(fields: Record, options?: IndexOptions) { const UNIQUE = { unique: true }; -const indexes: Partial> = { +const staticIndexes: Partial> = { scores: [index({ scoreID: 1 }, UNIQUE)], "score-pbs": [ index({ chartID: 1, userID: 1 }, UNIQUE), @@ -56,8 +56,28 @@ const indexes: Partial> = { index({ milestoneID: 1, userID: 1 }, UNIQUE), index({ userID: 1, game: 1, playtype: 1 }), ], + imports: [index({ importID: 1 }, UNIQUE)], + "import-timings": [ + index({ importID: 1 }, UNIQUE), + index({ timestamp: 1 }), + index({ total: 1 }), + ], + // @todo probably going to want some other ones. + users: [index({ id: 1 }, UNIQUE)], + tierlist: [ + index({ tierlistID: 1 }, UNIQUE), + index({ game: 1, playtype: 1, isDefault: 1 }, UNIQUE), + ], + folders: [ + index({ folderID: 1 }, UNIQUE), + index({ game: 1, playtype: 1 }), + index({ game: 1, playtype: 1, table: 1 }), + index({ game: 1, playtype: 1, table: 1, tableIndex: 1 }), + ], }; +const indexes: Partial> = staticIndexes; + for (const game of supportedGames) { indexes[`charts-${game}` as "charts-iidx"] = [ index({ chartID: 1 }, UNIQUE),