Skip to content

Commit 055e580

Browse files
committed
wip
1 parent aaabae1 commit 055e580

File tree

9 files changed

+133
-22
lines changed

9 files changed

+133
-22
lines changed

meteor/server/migration/api.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
} from './upgrades'
2323
import { ShowStyleBaseId, StudioId } from '@sofie-automation/corelib/dist/dataModel/Ids'
2424
import { BlueprintValidateConfigForStudioResult } from '@sofie-automation/corelib/dist/worker/studio'
25+
import { runUpgradeForCoreSystem } from './upgrades/system'
2526

2627
class ServerMigrationAPI extends MethodContextAPI implements NewMigrationAPI {
2728
async getMigrationStatus() {
@@ -123,5 +124,11 @@ class ServerMigrationAPI extends MethodContextAPI implements NewMigrationAPI {
123124

124125
return runUpgradeForShowStyleBase(showStyleBaseId)
125126
}
127+
128+
async runUpgradeForCoreSystem(): Promise<void> {
129+
await SystemWriteAccess.migrations(this)
130+
131+
return runUpgradeForCoreSystem()
132+
}
126133
}
127134
registerClassToMeteorMethods(MigrationAPIMethods, ServerMigrationAPI, false)

meteor/server/migration/upgrades/system.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import { Meteor } from 'meteor/meteor'
2-
import { getCoreSystemAsync } from '../../coreSystem/collection'
32
import { logger } from '../../logging'
43
import { Blueprints, CoreSystem } from '../../collections'
54
import { BlueprintManifestType, SystemBlueprintManifest } from '@sofie-automation/blueprints-integration'
65
import { evalBlueprint } from '../../api/blueprints/cache'
76
import { CommonContext } from './context'
87
import { updateTriggeredActionsForShowStyleBaseId } from './lib'
9-
import { SYSTEM_ID } from '@sofie-automation/meteor-lib/dist/collections/CoreSystem'
8+
import { CoreSystemId } from '@sofie-automation/corelib/dist/dataModel/Ids'
109

11-
export async function runUpgradeForCoreSystem(): Promise<void> {
10+
export async function runUpgradeForCoreSystem(coreSystemId: CoreSystemId): Promise<void> {
1211
logger.info(`Running upgrade for CoreSystem`)
1312

14-
const { coreSystem, blueprint, blueprintManifest } = await loadCoreSystemAndBlueprint()
13+
const { coreSystem, blueprint, blueprintManifest } = await loadCoreSystemAndBlueprint(coreSystemId)
1514

1615
if (typeof blueprintManifest.applyConfig !== 'function')
1716
throw new Meteor.Error(500, 'Blueprint does not support this config flow')
@@ -23,23 +22,25 @@ export async function runUpgradeForCoreSystem(): Promise<void> {
2322

2423
const result = blueprintManifest.applyConfig(blueprintContext)
2524

26-
await CoreSystem.updateAsync(SYSTEM_ID, {
25+
await CoreSystem.updateAsync(coreSystemId, {
2726
$set: {
2827
// 'sourceLayersWithOverrides.defaults': normalizeArray(result.sourceLayers, '_id'),
2928
// 'outputLayersWithOverrides.defaults': normalizeArray(result.outputLayers, '_id'),
3029
lastBlueprintConfig: {
3130
blueprintHash: blueprint.blueprintHash,
3231
blueprintId: blueprint._id,
32+
blueprintConfigPresetId: '',
33+
config: {},
3334
},
3435
},
3536
})
3637

3738
await updateTriggeredActionsForShowStyleBaseId(null, result.triggeredActions)
3839
}
3940

40-
async function loadCoreSystemAndBlueprint() {
41-
const coreSystem = await getCoreSystemAsync()
42-
if (!coreSystem) throw new Meteor.Error(404, `CoreSystem not found!`)
41+
async function loadCoreSystemAndBlueprint(coreSystemId: CoreSystemId) {
42+
const coreSystem = await CoreSystem.findOneAsync(coreSystemId)
43+
if (!coreSystem) throw new Meteor.Error(404, `CoreSystem "${coreSystemId}" not found!`)
4344

4445
// if (!showStyleBase.blueprintConfigPresetId) throw new Meteor.Error(500, 'ShowStyleBase is missing config preset')
4546

meteor/server/publications/blueprintUpgradeStatus/checkStatus.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ import { joinObjectPathFragments, objectPathGet } from '@sofie-automation/coreli
1616
import { applyAndValidateOverrides } from '@sofie-automation/corelib/dist/settings/objectWithOverrides'
1717
import { generateTranslation } from '../../lib/tempLib'
1818
import { logger } from '../../logging'
19-
import { ShowStyleBaseFields, StudioFields } from './reactiveContentCache'
19+
import { CoreSystemFields, ShowStyleBaseFields, StudioFields } from './reactiveContentCache'
2020
import _ from 'underscore'
2121
import { UIBlueprintUpgradeStatusBase } from '@sofie-automation/meteor-lib/dist/api/upgradeStatus'
2222
import { stringifyError } from '@sofie-automation/shared-lib/dist/lib/stringifyError'
23+
import { ICoreSystem } from '@sofie-automation/meteor-lib/dist/collections/CoreSystem'
2324

2425
export interface BlueprintMapEntry {
2526
_id: BlueprintId
@@ -31,7 +32,7 @@ export interface BlueprintMapEntry {
3132

3233
export function checkDocUpgradeStatus(
3334
blueprintMap: Map<BlueprintId, BlueprintMapEntry>,
34-
doc: Pick<DBStudio, StudioFields> | Pick<DBShowStyleBase, ShowStyleBaseFields>
35+
doc: Pick<ICoreSystem, CoreSystemFields> | Pick<DBStudio, StudioFields> | Pick<DBShowStyleBase, ShowStyleBaseFields>
3536
): Pick<UIBlueprintUpgradeStatusBase, 'invalidReason' | 'changes' | 'pendingRunOfFixupFunction'> {
3637
// Check the blueprintId is valid
3738
const blueprint = doc.blueprintId ? blueprintMap.get(doc.blueprintId) : null
@@ -101,7 +102,7 @@ export function checkDocUpgradeStatus(
101102
changes.push(generateTranslation('Blueprint has a new version'))
102103
}
103104

104-
if (doc.lastBlueprintConfig) {
105+
if (doc.lastBlueprintConfig && doc.blueprintConfigWithOverrides) {
105106
// Check if the config blob has changed since last run
106107
const newConfig = applyAndValidateOverrides(doc.blueprintConfigWithOverrides).obj
107108
const oldConfig = doc.lastBlueprintConfig.config

meteor/server/publications/blueprintUpgradeStatus/publication.ts

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ import {
1313
import { logger } from '../../logging'
1414
import { resolveCredentials } from '../../security/lib/credentials'
1515
import { NoSecurityReadAccess } from '../../security/noSecurity'
16-
import { ContentCache, createReactiveContentCache, ShowStyleBaseFields, StudioFields } from './reactiveContentCache'
16+
import {
17+
ContentCache,
18+
CoreSystemFields,
19+
createReactiveContentCache,
20+
ShowStyleBaseFields,
21+
StudioFields,
22+
} from './reactiveContentCache'
1723
import { UpgradesContentObserver } from './upgradesContentObserver'
1824
import { BlueprintMapEntry, checkDocUpgradeStatus } from './checkStatus'
1925
import { BlueprintManifestType } from '@sofie-automation/blueprints-integration'
@@ -23,6 +29,7 @@ import {
2329
UIBlueprintUpgradeStatus,
2430
UIBlueprintUpgradeStatusId,
2531
} from '@sofie-automation/meteor-lib/dist/api/upgradeStatus'
32+
import { ICoreSystem } from '@sofie-automation/meteor-lib/dist/collections/CoreSystem'
2633

2734
type BlueprintUpgradeStatusArgs = Record<string, never>
2835

@@ -33,6 +40,7 @@ export interface BlueprintUpgradeStatusState {
3340
interface BlueprintUpgradeStatusUpdateProps {
3441
newCache: ContentCache
3542

43+
invalidateSystem: boolean
3644
invalidateStudioIds: StudioId[]
3745
invalidateShowStyleBaseIds: ShowStyleBaseId[]
3846
invalidateBlueprintIds: BlueprintId[]
@@ -54,6 +62,11 @@ async function setupBlueprintUpgradeStatusPublicationObservers(
5462
return [
5563
mongoObserver,
5664

65+
cache.CoreSystem.find({}).observeChanges({
66+
added: () => triggerUpdate({ invalidateSystem: true }),
67+
changed: () => triggerUpdate({ invalidateSystem: true }),
68+
removed: () => triggerUpdate({ invalidateSystem: true }),
69+
}),
5770
cache.Studios.find({}).observeChanges({
5871
added: (id) => triggerUpdate({ invalidateStudioIds: [protectString(id)] }),
5972
changed: (id) => triggerUpdate({ invalidateStudioIds: [protectString(id)] }),
@@ -72,7 +85,10 @@ async function setupBlueprintUpgradeStatusPublicationObservers(
7285
]
7386
}
7487

75-
function getDocumentId(type: 'studio' | 'showStyle', id: ProtectedString<any>): UIBlueprintUpgradeStatusId {
88+
function getDocumentId(
89+
type: 'coreSystem' | 'studio' | 'showStyle',
90+
id: ProtectedString<any>
91+
): UIBlueprintUpgradeStatusId {
7692
return protectString(`${type}:${id}`)
7793
}
7894

@@ -100,6 +116,7 @@ export async function manipulateBlueprintUpgradeStatusPublicationData(
100116

101117
const studioBlueprintsMap = new Map<BlueprintId, BlueprintMapEntry>()
102118
const showStyleBlueprintsMap = new Map<BlueprintId, BlueprintMapEntry>()
119+
const systemBlueprintsMap = new Map<BlueprintId, BlueprintMapEntry>()
103120
state.contentCache.Blueprints.find({}).forEach((blueprint) => {
104121
switch (blueprint.blueprintType) {
105122
case BlueprintManifestType.SHOWSTYLE:
@@ -120,6 +137,15 @@ export async function manipulateBlueprintUpgradeStatusPublicationData(
120137
hasFixUpFunction: blueprint.hasFixUpFunction,
121138
})
122139
break
140+
case BlueprintManifestType.SYSTEM:
141+
systemBlueprintsMap.set(blueprint._id, {
142+
_id: blueprint._id,
143+
configPresets: {},
144+
configSchema: undefined, // TODO
145+
blueprintHash: blueprint.blueprintHash,
146+
hasFixUpFunction: false,
147+
})
148+
break
123149
// TODO - default?
124150
}
125151
})
@@ -136,6 +162,10 @@ export async function manipulateBlueprintUpgradeStatusPublicationData(
136162
state.contentCache.ShowStyleBases.find({}).forEach((showStyleBase) => {
137163
updateShowStyleUpgradeStatus(collection, showStyleBlueprintsMap, showStyleBase)
138164
})
165+
166+
state.contentCache.CoreSystem.find({}).forEach((coreSystem) => {
167+
updateCoreSystemUpgradeStatus(collection, systemBlueprintsMap, coreSystem)
168+
})
139169
} else {
140170
const regenerateForStudioIds = new Set(updateProps.invalidateStudioIds)
141171
const regenerateForShowStyleBaseIds = new Set(updateProps.invalidateShowStyleBaseIds)
@@ -181,9 +211,31 @@ export async function manipulateBlueprintUpgradeStatusPublicationData(
181211
collection.remove(getDocumentId('showStyle', showStyleBaseId))
182212
}
183213
}
214+
215+
if (updateProps.invalidateSystem) {
216+
state.contentCache.CoreSystem.find({}).forEach((coreSystem) => {
217+
updateCoreSystemUpgradeStatus(collection, systemBlueprintsMap, coreSystem)
218+
})
219+
}
184220
}
185221
}
186222

223+
function updateCoreSystemUpgradeStatus(
224+
collection: CustomPublishCollection<UIBlueprintUpgradeStatus>,
225+
blueprintsMap: Map<BlueprintId, BlueprintMapEntry>,
226+
coreSystem: Pick<ICoreSystem, CoreSystemFields>
227+
) {
228+
const status = checkDocUpgradeStatus(blueprintsMap, coreSystem)
229+
230+
collection.replace({
231+
...status,
232+
_id: getDocumentId('coreSystem', coreSystem._id),
233+
documentType: 'coreSystem',
234+
documentId: coreSystem._id,
235+
name: coreSystem.name ?? 'System',
236+
})
237+
}
238+
187239
function updateStudioUpgradeStatus(
188240
collection: CustomPublishCollection<UIBlueprintUpgradeStatus>,
189241
blueprintsMap: Map<BlueprintId, BlueprintMapEntry>,

meteor/server/publications/blueprintUpgradeStatus/reactiveContentCache.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@ import { MongoFieldSpecifierOnesStrict } from '@sofie-automation/corelib/dist/mo
44
import { DBStudio } from '@sofie-automation/corelib/dist/dataModel/Studio'
55
import { DBShowStyleBase } from '@sofie-automation/corelib/dist/dataModel/ShowStyleBase'
66
import { Blueprint } from '@sofie-automation/corelib/dist/dataModel/Blueprint'
7+
import { ICoreSystem } from '@sofie-automation/meteor-lib/dist/collections/CoreSystem'
8+
9+
export type CoreSystemFields =
10+
| '_id'
11+
| 'blueprintId'
12+
| 'blueprintConfigPresetId'
13+
| 'lastBlueprintConfig'
14+
| 'blueprintConfigWithOverrides'
15+
| 'lastBlueprintFixUpHash'
16+
| 'name'
17+
export const coreSystemFieldsSpecifier = literal<MongoFieldSpecifierOnesStrict<Pick<ICoreSystem, CoreSystemFields>>>({
18+
_id: 1,
19+
blueprintId: 1,
20+
blueprintConfigPresetId: 1,
21+
lastBlueprintConfig: 1,
22+
lastBlueprintFixUpHash: 1,
23+
blueprintConfigWithOverrides: 1,
24+
name: 1,
25+
})
726

827
export type StudioFields =
928
| '_id'
@@ -64,13 +83,15 @@ export const blueprintFieldSpecifier = literal<MongoFieldSpecifierOnesStrict<Pic
6483
})
6584

6685
export interface ContentCache {
86+
CoreSystem: ReactiveCacheCollection<Pick<ICoreSystem, CoreSystemFields>>
6787
Studios: ReactiveCacheCollection<Pick<DBStudio, StudioFields>>
6888
ShowStyleBases: ReactiveCacheCollection<Pick<DBShowStyleBase, ShowStyleBaseFields>>
6989
Blueprints: ReactiveCacheCollection<Pick<Blueprint, BlueprintFields>>
7090
}
7191

7292
export function createReactiveContentCache(): ContentCache {
7393
const cache: ContentCache = {
94+
CoreSystem: new ReactiveCacheCollection<Pick<ICoreSystem, CoreSystemFields>>('coreSystem'),
7495
Studios: new ReactiveCacheCollection<Pick<DBStudio, StudioFields>>('studios'),
7596
ShowStyleBases: new ReactiveCacheCollection<Pick<DBShowStyleBase, ShowStyleBaseFields>>('showStyleBases'),
7697
Blueprints: new ReactiveCacheCollection<Pick<Blueprint, BlueprintFields>>('blueprints'),

meteor/server/publications/blueprintUpgradeStatus/upgradesContentObserver.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { logger } from '../../logging'
33
import {
44
blueprintFieldSpecifier,
55
ContentCache,
6+
coreSystemFieldsSpecifier,
67
showStyleFieldSpecifier,
78
studioFieldSpecifier,
89
} from './reactiveContentCache'
9-
import { Blueprints, ShowStyleBases, Studios } from '../../collections'
10+
import { Blueprints, CoreSystem, ShowStyleBases, Studios } from '../../collections'
1011
import { waitForAllObserversReady } from '../lib/lib'
1112

1213
export class UpgradesContentObserver {
@@ -22,6 +23,9 @@ export class UpgradesContentObserver {
2223
logger.silly(`Creating UpgradesContentObserver`)
2324

2425
const observers = await waitForAllObserversReady([
26+
CoreSystem.observeChanges({}, cache.CoreSystem.link(), {
27+
projection: coreSystemFieldsSpecifier,
28+
}),
2529
Studios.observeChanges({}, cache.Studios.link(), {
2630
projection: studioFieldSpecifier,
2731
}),

packages/meteor-lib/src/api/migration.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { MigrationStepInput, MigrationStepInputResult } from '@sofie-automation/blueprints-integration'
2-
import { BlueprintId, ShowStyleBaseId, SnapshotId, StudioId } from '@sofie-automation/corelib/dist/dataModel/Ids'
2+
import {
3+
BlueprintId,
4+
CoreSystemId,
5+
ShowStyleBaseId,
6+
SnapshotId,
7+
StudioId,
8+
} from '@sofie-automation/corelib/dist/dataModel/Ids'
39
import { ITranslatableMessage } from '@sofie-automation/corelib/dist/TranslatableMessage'
410
import { BlueprintValidateConfigForStudioResult } from '@sofie-automation/corelib/dist/worker/studio'
511

@@ -64,10 +70,15 @@ export interface NewMigrationAPI {
6470
validateConfigForShowStyleBase(showStyleBaseId: ShowStyleBaseId): Promise<BlueprintValidateConfigForStudioResult>
6571

6672
/**
67-
* Run `applyConfig` on the blueprint for a Studio, and store the results into the db
68-
* @param studioId Id of the Studio
73+
* Run `applyConfig` on the blueprint for a ShowStyleBase, and store the results into the db
74+
* @param showStyleBaseId Id of the ShowStyleBase
6975
*/
7076
runUpgradeForShowStyleBase(showStyleBaseId: ShowStyleBaseId): Promise<void>
77+
78+
/**
79+
* Run `applyConfig` on the blueprint for the CoreSystem, and store the results into the db
80+
*/
81+
runUpgradeForCoreSystem(coreSystemId: CoreSystemId): Promise<void>
7182
}
7283

7384
export enum MigrationAPIMethods {
@@ -85,6 +96,7 @@ export enum MigrationAPIMethods {
8596
'ignoreFixupConfigForShowStyleBase' = 'migration.ignoreFixupConfigForShowStyleBase',
8697
'validateConfigForShowStyleBase' = 'migration.validateConfigForShowStyleBase',
8798
'runUpgradeForShowStyleBase' = 'migration.runUpgradeForShowStyleBase',
99+
'runUpgradeForCoreSystem' = 'migration.runUpgradeForCoreSystem',
88100
}
89101

90102
export interface GetMigrationStatusResult {

packages/meteor-lib/src/api/upgradeStatus.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { ITranslatableMessage } from '@sofie-automation/blueprints-integration'
2-
import { StudioId, ShowStyleBaseId } from '@sofie-automation/corelib/dist/dataModel/Ids'
2+
import { StudioId, ShowStyleBaseId, CoreSystemId } from '@sofie-automation/corelib/dist/dataModel/Ids'
33
import { ProtectedString } from '@sofie-automation/corelib/dist/protectedString'
44

55
export type UIBlueprintUpgradeStatusId = ProtectedString<'UIBlueprintUpgradeStatus'>
66

7-
export type UIBlueprintUpgradeStatus = UIBlueprintUpgradeStatusStudio | UIBlueprintUpgradeStatusShowStyle
7+
export type UIBlueprintUpgradeStatus =
8+
| UIBlueprintUpgradeStatusCoreSystem
9+
| UIBlueprintUpgradeStatusStudio
10+
| UIBlueprintUpgradeStatusShowStyle
811

912
export interface UIBlueprintUpgradeStatusBase {
1013
_id: UIBlueprintUpgradeStatusId
1114

12-
documentType: 'studio' | 'showStyle'
13-
documentId: StudioId | ShowStyleBaseId
15+
documentType: 'coreSystem' | 'studio' | 'showStyle'
16+
documentId: CoreSystemId | StudioId | ShowStyleBaseId
1417

1518
name: string
1619

@@ -30,6 +33,11 @@ export interface UIBlueprintUpgradeStatusBase {
3033
changes: ITranslatableMessage[]
3134
}
3235

36+
export interface UIBlueprintUpgradeStatusCoreSystem extends UIBlueprintUpgradeStatusBase {
37+
documentType: 'coreSystem'
38+
documentId: CoreSystemId
39+
}
40+
3341
export interface UIBlueprintUpgradeStatusStudio extends UIBlueprintUpgradeStatusBase {
3442
documentType: 'studio'
3543
documentId: StudioId

packages/meteor-lib/src/collections/CoreSystem.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,12 @@ export interface ICoreSystem {
113113
* Note: This doesn't currently have any 'config' which it relates to.
114114
* The name is to be consistent with studio/showstyle, and in preparation for their being config/configpresets used here
115115
*/
116-
lastBlueprintConfig: Omit<LastBlueprintConfig, 'blueprintConfigPresetId' | 'config'> | undefined
116+
lastBlueprintConfig: LastBlueprintConfig | undefined
117+
118+
/** These fields are to have type consistency with the full config driven upgrades flow, but we don't use them yet */
119+
blueprintConfigPresetId?: undefined
120+
lastBlueprintFixUpHash?: undefined
121+
blueprintConfigWithOverrides?: undefined
117122
}
118123

119124
/** In the beginning, there was the database, and the database was with Sofie, and the database was Sofie.

0 commit comments

Comments
 (0)