|
1 | 1 | import { addMigrationSteps } from './databaseMigration' |
2 | 2 | import { CURRENT_SYSTEM_VERSION } from './currentSystemVersion' |
3 | 3 | import { MongoInternals } from 'meteor/mongo' |
4 | | -import { Studios } from '../collections' |
| 4 | +import { RundownPlaylists, Studios } from '../collections' |
5 | 5 | import { ExpectedPackages } from '../collections' |
6 | 6 | import * as PackagesPreR53 from '@sofie-automation/corelib/dist/dataModel/Old/ExpectedPackagesR52' |
7 | 7 | import { |
@@ -195,4 +195,48 @@ export const addSteps = addMigrationSteps(CURRENT_SYSTEM_VERSION, [ |
195 | 195 | } |
196 | 196 | }, |
197 | 197 | }, |
| 198 | + { |
| 199 | + id: `Rename previousPersistentState to privatePlayoutPersistentState`, |
| 200 | + canBeRunAutomatically: true, |
| 201 | + validate: async () => { |
| 202 | + const playlists = await RundownPlaylists.countDocuments({ |
| 203 | + previousPersistentState: { $exists: true }, |
| 204 | + privatePlayoutPersistentState: { $exists: false }, |
| 205 | + }) |
| 206 | + if (playlists > 0) { |
| 207 | + return 'One or more Playlists has previousPersistentState field that needs to be renamed to privatePlayoutPersistentState' |
| 208 | + } |
| 209 | + |
| 210 | + return false |
| 211 | + }, |
| 212 | + migrate: async () => { |
| 213 | + const playlists = await RundownPlaylists.findFetchAsync( |
| 214 | + { |
| 215 | + previousPersistentState: { $exists: true }, |
| 216 | + privatePlayoutPersistentState: { $exists: false }, |
| 217 | + }, |
| 218 | + { |
| 219 | + projection: { |
| 220 | + _id: 1, |
| 221 | + // @ts-expect-error - This field is being renamed, so it won't exist on the type anymore |
| 222 | + previousPersistentState: 1, |
| 223 | + }, |
| 224 | + } |
| 225 | + ) |
| 226 | + |
| 227 | + for (const playlist of playlists) { |
| 228 | + // @ts-expect-error - This field is being renamed, so it won't exist on the type anymore |
| 229 | + const previousPersistentState = playlist.previousPersistentState |
| 230 | + |
| 231 | + await RundownPlaylists.mutableCollection.updateAsync(playlist._id, { |
| 232 | + $set: { |
| 233 | + privatePlayoutPersistentState: previousPersistentState, |
| 234 | + }, |
| 235 | + $unset: { |
| 236 | + previousPersistentState: 1, |
| 237 | + }, |
| 238 | + }) |
| 239 | + } |
| 240 | + }, |
| 241 | + }, |
198 | 242 | ]) |
0 commit comments