diff --git a/server/src/scripts/sync-database.ts b/server/src/scripts/sync-database.ts index f1fcfcecd..10290e4b6 100644 --- a/server/src/scripts/sync-database.ts +++ b/server/src/scripts/sync-database.ts @@ -7,6 +7,7 @@ import { PullDatabaseSeeds } from "lib/database-seeds/repo"; import CreateLogCtx, { KtLogger } from "lib/logger/logger"; import UpdateIsPrimaryStatus from "lib/score-mutation/update-isprimary"; import { TachiConfig } from "lib/setup/config"; +import { UpdateMilestoneSubscriptions } from "lib/targets/milestones"; import { BulkWriteOperation } from "mongodb"; import { ICollection } from "monk"; import { @@ -263,6 +264,43 @@ const syncInstructions: SyncInstructions[] = [ ); }, }, + { + pattern: /^milestone-sets/u, + handler: async ( + milestoneSets: MilestoneSetDocument[], + collection: ICollection, + logger + ) => { + // removing and updating these is fine. Users cannot subscibe to sets. + await GenericUpsert( + milestoneSets.filter((e) => IsSupported(e.game)), + collection, + "setID", + logger + ); + }, + }, + { + pattern: /^milestones/u, + handler: async ( + milestones: MilestoneDocument[], + collection: ICollection, + logger + ) => { + const r = await GenericUpsert( + milestones.filter((e) => IsSupported(e.game)), + collection, + "milestoneID", + logger + ); + + if (r.thingsChanged) { + const affectedMilestoneIDs = r.changedFields as string[]; + + await Promise.all(affectedMilestoneIDs.map((e) => UpdateMilestoneSubscriptions(e))); + } + }, + }, ]; const logger = CreateLogCtx("Database Sync");