|
1 | 1 | import { addMigrationSteps } from './databaseMigration' |
2 | 2 | import { CURRENT_SYSTEM_VERSION } from './currentSystemVersion' |
3 | | -import { RundownPlaylists } from '../collections' |
| 3 | +import { RundownPlaylists, Segments, Studios } from '../collections' |
4 | 4 | import { ContainerIdsToObjectWithOverridesMigrationStep } from './steps/X_X_X/ContainerIdsToObjectWithOverridesMigrationStep' |
| 5 | +import { ShelfButtonSize } from '@sofie-automation/shared-lib/dist/core/model/StudioSettings' |
5 | 6 |
|
6 | 7 | /* |
7 | 8 | * ************************************************************************************** |
@@ -83,5 +84,69 @@ export const addSteps = addMigrationSteps(CURRENT_SYSTEM_VERSION, [ |
83 | 84 | ) |
84 | 85 | }, |
85 | 86 | }, |
| 87 | + { |
| 88 | + id: `studios settings create default shelfAdlibButtonSize=large`, |
| 89 | + canBeRunAutomatically: true, |
| 90 | + validate: async () => { |
| 91 | + const studios = await Studios.findFetchAsync({ |
| 92 | + 'settingsWithOverrides.defaults.shelfAdlibButtonSize': { $exists: false }, |
| 93 | + }) |
| 94 | + |
| 95 | + if (studios.length > 0) return `Some studios are missing settings default shelfAdlibButtonSize` |
| 96 | + return false |
| 97 | + }, |
| 98 | + migrate: async () => { |
| 99 | + const studios = await Studios.findFetchAsync({ |
| 100 | + 'settingsWithOverrides.defaults.shelfAdlibButtonSize': { $exists: false }, |
| 101 | + }) |
| 102 | + |
| 103 | + for (const studio of studios) { |
| 104 | + await Studios.updateAsync(studio._id, { |
| 105 | + $set: { |
| 106 | + 'settingsWithOverrides.defaults.shelfAdlibButtonSize': ShelfButtonSize.LARGE, |
| 107 | + }, |
| 108 | + }) |
| 109 | + } |
| 110 | + }, |
| 111 | + }, |
| 112 | + { |
| 113 | + id: `segments migrate showShelf to displayMinishelf`, |
| 114 | + canBeRunAutomatically: true, |
| 115 | + validate: async () => { |
| 116 | + const count = await Segments.countDocuments({ |
| 117 | + showShelf: { $exists: true }, |
| 118 | + }) |
| 119 | + if (count > 0) return `There are ${count} Segments with legacy showShelf` |
| 120 | + return false |
| 121 | + }, |
| 122 | + migrate: async () => { |
| 123 | + // showShelf: true => displayMinishelf: inherit (if missing) |
| 124 | + await Segments.mutableCollection.updateAsync( |
| 125 | + { |
| 126 | + showShelf: true, |
| 127 | + displayMinishelf: { $exists: false }, |
| 128 | + }, |
| 129 | + { |
| 130 | + $set: { |
| 131 | + displayMinishelf: ShelfButtonSize.INHERIT, |
| 132 | + }, |
| 133 | + }, |
| 134 | + { multi: true } |
| 135 | + ) |
| 136 | + |
| 137 | + // Always remove legacy field |
| 138 | + await Segments.mutableCollection.updateAsync( |
| 139 | + { |
| 140 | + showShelf: { $exists: true }, |
| 141 | + }, |
| 142 | + { |
| 143 | + $unset: { |
| 144 | + showShelf: 1, |
| 145 | + }, |
| 146 | + }, |
| 147 | + { multi: true } |
| 148 | + ) |
| 149 | + }, |
| 150 | + }, |
86 | 151 | // Add your migration here |
87 | 152 | ]) |
0 commit comments