11import { addMigrationSteps } from './databaseMigration'
22import { CURRENT_SYSTEM_VERSION } from './currentSystemVersion'
3- import { MongoInternals } from 'meteor/mongo'
4- import { RundownPlaylists , Studios } from '../collections'
5- import { ExpectedPackages } from '../collections'
6- import * as PackagesPreR53 from '@sofie-automation/corelib/dist/dataModel/Old/ExpectedPackagesR52'
7- import {
8- ExpectedPackageDB ,
9- ExpectedPackageIngestSource ,
10- } from '@sofie-automation/corelib/dist/dataModel/ExpectedPackages'
11- import { BucketId , RundownId } from '@sofie-automation/corelib/dist/dataModel/Ids'
12- import { assertNever , Complete } from '@sofie-automation/corelib/dist/lib'
3+ import { RundownPlaylists } from '../collections'
134import { ContainerIdsToObjectWithOverridesMigrationStep } from './steps/X_X_X/ContainerIdsToObjectWithOverridesMigrationStep'
145
156/*
@@ -23,181 +14,6 @@ import { ContainerIdsToObjectWithOverridesMigrationStep } from './steps/X_X_X/Co
2314 */
2415
2516export const addSteps = addMigrationSteps ( CURRENT_SYSTEM_VERSION , [
26- {
27- id : `Drop media manager collections` ,
28- canBeRunAutomatically : true ,
29- validate : async ( ) => {
30- // If MongoInternals is not available, we are in a test environment
31- if ( ! MongoInternals ) return false
32-
33- const existingCollections = await MongoInternals . defaultRemoteCollectionDriver ( )
34- . mongo . db . listCollections ( )
35- . toArray ( )
36- const collectionsToDrop = existingCollections . filter ( ( c ) =>
37- [ 'expectedMediaItems' , 'mediaWorkFlows' , 'mediaWorkFlowSteps' ] . includes ( c . name )
38- )
39- if ( collectionsToDrop . length > 0 ) {
40- return `There are ${ collectionsToDrop . length } obsolete collections to be removed: ${ collectionsToDrop
41- . map ( ( c ) => c . name )
42- . join ( ', ' ) } `
43- }
44-
45- return false
46- } ,
47- migrate : async ( ) => {
48- const existingCollections = await MongoInternals . defaultRemoteCollectionDriver ( )
49- . mongo . db . listCollections ( )
50- . toArray ( )
51- const collectionsToDrop = existingCollections . filter ( ( c ) =>
52- [ 'expectedMediaItems' , 'mediaWorkFlows' , 'mediaWorkFlowSteps' ] . includes ( c . name )
53- )
54- for ( const c of collectionsToDrop ) {
55- await MongoInternals . defaultRemoteCollectionDriver ( ) . mongo . db . dropCollection ( c . name )
56- }
57- } ,
58- } ,
59-
60- {
61- id : 'Ensure a single studio' ,
62- canBeRunAutomatically : true ,
63- validate : async ( ) => {
64- const studioCount = await Studios . countDocuments ( )
65- if ( studioCount === 0 ) return `No studios found`
66- if ( studioCount > 1 ) return `There are ${ studioCount } studios, but only one is supported`
67- return false
68- } ,
69- migrate : async ( ) => {
70- // Do nothing, the user will have to resolve this manually
71- } ,
72- } ,
73- {
74- id : `convert ExpectedPackages to new format` ,
75- canBeRunAutomatically : true ,
76- validate : async ( ) => {
77- const packages = await ExpectedPackages . findFetchAsync ( {
78- fromPieceType : { $exists : true } ,
79- } )
80-
81- if ( packages . length > 0 ) {
82- return 'ExpectedPackages must be converted to new format'
83- }
84-
85- return false
86- } ,
87- migrate : async ( ) => {
88- const packages = ( await ExpectedPackages . findFetchAsync ( {
89- fromPieceType : { $exists : true } ,
90- } ) ) as unknown as PackagesPreR53 . ExpectedPackageDB [ ]
91-
92- for ( const pkg of packages ) {
93- let rundownId : RundownId | null = null
94- let bucketId : BucketId | null = null
95- let ingestSource : ExpectedPackageIngestSource | undefined
96-
97- switch ( pkg . fromPieceType ) {
98- case PackagesPreR53 . ExpectedPackageDBType . PIECE :
99- case PackagesPreR53 . ExpectedPackageDBType . ADLIB_PIECE :
100- rundownId = pkg . rundownId
101- ingestSource = {
102- fromPieceType : pkg . fromPieceType ,
103- pieceId : pkg . pieceId ,
104- partId : pkg . partId ,
105- segmentId : pkg . segmentId ,
106- blueprintPackageId : pkg . blueprintPackageId ,
107- listenToPackageInfoUpdates : pkg . listenToPackageInfoUpdates ,
108- }
109- break
110- case PackagesPreR53 . ExpectedPackageDBType . ADLIB_ACTION :
111- rundownId = pkg . rundownId
112- ingestSource = {
113- fromPieceType : pkg . fromPieceType ,
114- pieceId : pkg . pieceId ,
115- partId : pkg . partId ,
116- segmentId : pkg . segmentId ,
117- blueprintPackageId : pkg . blueprintPackageId ,
118- listenToPackageInfoUpdates : pkg . listenToPackageInfoUpdates ,
119- }
120- break
121- case PackagesPreR53 . ExpectedPackageDBType . BASELINE_ADLIB_PIECE :
122- rundownId = pkg . rundownId
123- ingestSource = {
124- fromPieceType : pkg . fromPieceType ,
125- pieceId : pkg . pieceId ,
126- blueprintPackageId : pkg . blueprintPackageId ,
127- listenToPackageInfoUpdates : pkg . listenToPackageInfoUpdates ,
128- }
129- break
130- case PackagesPreR53 . ExpectedPackageDBType . BASELINE_ADLIB_ACTION :
131- rundownId = pkg . rundownId
132- ingestSource = {
133- fromPieceType : pkg . fromPieceType ,
134- pieceId : pkg . pieceId ,
135- blueprintPackageId : pkg . blueprintPackageId ,
136- listenToPackageInfoUpdates : pkg . listenToPackageInfoUpdates ,
137- }
138- break
139- case PackagesPreR53 . ExpectedPackageDBType . RUNDOWN_BASELINE_OBJECTS :
140- rundownId = pkg . rundownId
141- ingestSource = {
142- fromPieceType : pkg . fromPieceType ,
143- blueprintPackageId : pkg . blueprintPackageId ,
144- listenToPackageInfoUpdates : pkg . listenToPackageInfoUpdates ,
145- }
146- break
147- case PackagesPreR53 . ExpectedPackageDBType . BUCKET_ADLIB :
148- bucketId = pkg . bucketId
149- ingestSource = {
150- fromPieceType : pkg . fromPieceType ,
151- pieceId : pkg . pieceId ,
152- pieceExternalId : pkg . pieceExternalId ,
153- blueprintPackageId : pkg . blueprintPackageId ,
154- listenToPackageInfoUpdates : pkg . listenToPackageInfoUpdates ,
155- }
156- break
157- case PackagesPreR53 . ExpectedPackageDBType . BUCKET_ADLIB_ACTION :
158- bucketId = pkg . bucketId
159- ingestSource = {
160- fromPieceType : pkg . fromPieceType ,
161- pieceId : pkg . pieceId ,
162- pieceExternalId : pkg . pieceExternalId ,
163- blueprintPackageId : pkg . blueprintPackageId ,
164- listenToPackageInfoUpdates : pkg . listenToPackageInfoUpdates ,
165- }
166- break
167- case PackagesPreR53 . ExpectedPackageDBType . STUDIO_BASELINE_OBJECTS :
168- ingestSource = {
169- fromPieceType : pkg . fromPieceType ,
170- blueprintPackageId : pkg . blueprintPackageId ,
171- listenToPackageInfoUpdates : pkg . listenToPackageInfoUpdates ,
172- }
173- break
174- default :
175- assertNever ( pkg )
176- break
177- }
178-
179- await ExpectedPackages . mutableCollection . removeAsync ( pkg . _id )
180-
181- if ( ingestSource ) {
182- await ExpectedPackages . mutableCollection . insertAsync ( {
183- _id : pkg . _id , // Preserve the old id to ensure references aren't broken. This will be 'corrected' upon first ingest operation
184- studioId : pkg . studioId ,
185- rundownId : rundownId ,
186- bucketId : bucketId ,
187- package : {
188- ...( pkg as any ) , // Some fields should be pruned off this, but this is fine
189- _id : pkg . blueprintPackageId ,
190- } ,
191- created : pkg . created ,
192- ingestSources : [ ingestSource ] ,
193- playoutSources : {
194- pieceInstanceIds : [ ] ,
195- } ,
196- } satisfies Complete < ExpectedPackageDB > )
197- }
198- }
199- } ,
200- } ,
20117 {
20218 id : `Rename previousPersistentState to privatePlayoutPersistentState` ,
20319 canBeRunAutomatically : true ,
0 commit comments