@@ -15,6 +15,7 @@ import {
1515import { StudioId } from '@sofie-automation/corelib/dist/dataModel/Ids'
1616import { literal , unprotectString } from '../lib/tempLib'
1717import { logger } from '../logging'
18+ import { IngestDeviceSecretSettingsStatus } from '@sofie-automation/corelib/src/dataModel/PeripheralDeviceSettings/ingestDevice'
1819
1920/*
2021 * **************************************************************************************
@@ -230,9 +231,53 @@ export const addSteps = addMigrationSteps(CURRENT_SYSTEM_VERSION, [
230231 } ,
231232
232233 {
233- id : `move PeripheralDevice settings to studio ` ,
234+ id : `PeripheralDevice populate secretSettingsStatus ` ,
234235 canBeRunAutomatically : true ,
235236 dependOnResultFrom : `studios create peripheralDeviceSettings.deviceSettings` ,
237+ validate : async ( ) => {
238+ const devices = await PeripheralDevices . findFetchAsync ( {
239+ secretSettings : { $exists : true } ,
240+ settings : { $exists : true } ,
241+ secretSettingsStatus : { $exists : false } ,
242+ } )
243+
244+ if ( devices . length > 0 ) {
245+ return 'settings must be moved to the studio'
246+ }
247+
248+ return false
249+ } ,
250+ migrate : async ( ) => {
251+ const devices = await PeripheralDevices . findFetchAsync ( {
252+ secretSettings : { $exists : true } ,
253+ settings : { $exists : true } ,
254+ secretSettingsStatus : { $exists : false } ,
255+ } )
256+
257+ for ( const device of devices ) {
258+ // @ts -expect-error settings is typed as Record<string, any>
259+ const oldSettings = device . settings as IngestDeviceSecretSettingsStatus | undefined
260+
261+ await PeripheralDevices . updateAsync ( device . _id , {
262+ $set : {
263+ secretSettingsStatus : {
264+ secretCredentials : oldSettings ?. secretCredentials ,
265+ secretAccessToken : oldSettings ?. secretAccessToken ,
266+ } ,
267+ } ,
268+ $unset : {
269+ 'settings.secretCredentials' : 1 ,
270+ 'settings.secretAccessToken' : 1 ,
271+ } ,
272+ } )
273+ }
274+ } ,
275+ } ,
276+
277+ {
278+ id : `move PeripheralDevice settings to studio` ,
279+ canBeRunAutomatically : true ,
280+ dependOnResultFrom : `PeripheralDevice populate secretSettingsStatus` ,
236281 validate : async ( ) => {
237282 const devices = await PeripheralDevices . findFetchAsync ( {
238283 studioId : { $exists : true } ,
0 commit comments