11import { Meteor } from 'meteor/meteor'
22import * as semver from 'semver'
33import {
4- InputFunctionCore ,
54 MigrateFunctionCore ,
65 MigrationStep ,
7- MigrationStepInput ,
8- MigrationStepInputFilteredResult ,
9- MigrationStepInputResult ,
106 ValidateFunctionCore ,
117 ValidateFunction ,
128 MigrateFunction ,
13- InputFunction ,
149 MigrationStepCore ,
15- } from '@sofie-automation/blueprints-integration '
10+ } from '@sofie-automation/meteor-lib/dist/migrations '
1611import _ from 'underscore'
1712import {
1813 GetMigrationStatusResult ,
@@ -24,7 +19,7 @@ import { logger } from '../logging'
2419import { internalStoreSystemSnapshot } from '../api/snapshot'
2520import { parseVersion , Version } from '../systemStatus/semverUtils'
2621import { GENESIS_SYSTEM_VERSION } from '@sofie-automation/meteor-lib/dist/collections/CoreSystem'
27- import { clone , getHash , omit } from '@sofie-automation/corelib/dist/lib'
22+ import { getHash , omit } from '@sofie-automation/corelib/dist/lib'
2823import { protectString } from '@sofie-automation/corelib/dist/protectedString'
2924import { stringifyError } from '@sofie-automation/shared-lib/dist/lib/stringifyError'
3025import { CURRENT_SYSTEM_VERSION } from './currentSystemVersion'
@@ -57,7 +52,7 @@ export function isVersionSupported(version: Version): boolean {
5752 return isSupported
5853}
5954
60- interface MigrationStepInternal extends MigrationStep < ValidateFunction , MigrateFunction , InputFunction > {
55+ interface MigrationStepInternal extends MigrationStep < ValidateFunction , MigrateFunction > {
6156 chunk : MigrationChunk
6257 _rank : number
6358 _version : Version // step version
@@ -94,7 +89,6 @@ export interface PreparedMigration {
9489 automaticStepCount : number
9590 manualStepCount : number
9691 ignoredStepCount : number
97- manualInputs : MigrationStepInput [ ]
9892 partialMigration : boolean
9993}
10094export async function prepareMigration ( returnAllChunks ?: boolean ) : Promise < PreparedMigration > {
@@ -130,7 +124,6 @@ export async function prepareMigration(returnAllChunks?: boolean): Promise<Prepa
130124 validate : step . validate ,
131125 canBeRunAutomatically : step . canBeRunAutomatically ,
132126 migrate : step . migrate ,
133- input : step . input ,
134127 dependOnResultFrom : step . dependOnResultFrom ,
135128 version : step . version ,
136129 _version : parseVersion ( step . version ) ,
@@ -167,9 +160,6 @@ export async function prepareMigration(returnAllChunks?: boolean): Promise<Prepa
167160 const ignoredSteps : { [ id : string ] : true } = { }
168161 let includesCoreStep = false
169162 for ( const step of allMigrationSteps ) {
170- if ( ! step . canBeRunAutomatically && ( ! step . input || ( Array . isArray ( step . input ) && ! step . input . length ) ) )
171- throw new Meteor . Error ( 500 , `MigrationStep "${ step . id } " is manual, but no input is provided` )
172-
173163 if ( step . chunk . sourceType !== MigrationStepType . CORE && includesCoreStep ) {
174164 // stop here as core migrations need to be run before anything else can
175165 partialMigration = true
@@ -232,39 +222,12 @@ export async function prepareMigration(returnAllChunks?: boolean): Promise<Prepa
232222 // check if there are any manual steps:
233223 // (this makes an automatic migration impossible)
234224
235- const manualInputs : Array < MigrationStepInput > = [ ]
236225 const stepsHash : Array < string > = [ ]
237226 for ( const step of Object . values < MigrationStepInternal > ( migrationSteps ) ) {
238227 stepsHash . push ( step . id )
239228 step . chunk . _steps . push ( step . id )
240229 if ( ! step . canBeRunAutomatically ) {
241230 manualStepCount ++
242-
243- if ( step . input ) {
244- let input : Array < MigrationStepInput > = [ ]
245- if ( Array . isArray ( step . input ) ) {
246- input = clone ( step . input )
247- } else if ( typeof step . input === 'function' ) {
248- if ( step . chunk . sourceType === MigrationStepType . CORE ) {
249- const inputFunction = step . input as InputFunctionCore
250- input = inputFunction ( )
251- } else throw new Meteor . Error ( 500 , `Unknown step.chunk.sourceType "${ step . chunk . sourceType } "` )
252- }
253- if ( input . length ) {
254- for ( const i of input ) {
255- if ( i . label && typeof step . _validateResult === 'string' ) {
256- i . label = ( i . label + '' ) . replace ( / \$ v a l i d a t i o n / g, step . _validateResult )
257- }
258- if ( i . description && typeof step . _validateResult === 'string' ) {
259- i . description = ( i . description + '' ) . replace ( / \$ v a l i d a t i o n / g, step . _validateResult )
260- }
261- manualInputs . push ( {
262- ...i ,
263- stepId : step . id ,
264- } )
265- }
266- }
267- }
268231 } else {
269232 automaticStepCount ++
270233 }
@@ -290,15 +253,13 @@ export async function prepareMigration(returnAllChunks?: boolean): Promise<Prepa
290253 automaticStepCount : automaticStepCount ,
291254 manualStepCount : manualStepCount ,
292255 ignoredStepCount : ignoredStepCount ,
293- manualInputs : manualInputs ,
294256 partialMigration : partialMigration ,
295257 }
296258}
297259
298260export async function runMigration (
299261 chunks : Array < MigrationChunk > ,
300262 hash : string ,
301- inputResults : Array < MigrationStepInputResult > ,
302263 isFirstOfPartialMigrations = true ,
303264 chunksLeft = 20
304265) : Promise < RunMigrationResult > {
@@ -312,19 +273,9 @@ export async function runMigration(
312273 // Verify the input:
313274 const migration = await prepareMigration ( true )
314275
315- const manualInputsWithUserPrompt = migration . manualInputs . filter ( ( manualInput ) => {
316- return ! ! ( manualInput . stepId && manualInput . attribute )
317- } )
318276 if ( migration . hash !== hash )
319277 throw new Meteor . Error ( 500 , `Migration input hash differ from expected: "${ hash } ", "${ migration . hash } "` )
320278
321- if ( manualInputsWithUserPrompt . length !== inputResults . length ) {
322- throw new Meteor . Error (
323- 500 ,
324- `Migration manualInput lengths differ from expected: "${ inputResults . length } ", "${ migration . manualInputs . length } "`
325- )
326- }
327-
328279 // Check that chunks match:
329280 let unmatchedChunk = migration . chunks . find ( ( migrationChunk ) => {
330281 return ! chunks . find ( ( chunk ) => {
@@ -375,26 +326,16 @@ export async function runMigration(
375326 `Migration: ${ migration . automaticStepCount } automatic and ${ migration . manualStepCount } manual steps (${ migration . ignoredStepCount } ignored).`
376327 )
377328
378- logger . debug ( inputResults )
379-
380329 for ( const step of migration . steps ) {
381330 try {
382- // Prepare input from user
383- const stepInput : MigrationStepInputFilteredResult = { }
384- for ( const ir of inputResults ) {
385- if ( ir . stepId === step . id ) {
386- stepInput [ ir . attribute ] = ir . value
387- }
388- }
389-
390331 // Run the migration script
391332
392333 if ( step . migrate !== undefined ) {
393334 logger . info ( `Running migration step "${ step . id } "` )
394335
395336 if ( step . chunk . sourceType === MigrationStepType . CORE ) {
396337 const migration = step . migrate as MigrateFunctionCore
397- await migration ( stepInput )
338+ await migration ( )
398339 } else throw new Meteor . Error ( 500 , `Unknown step.chunk.sourceType "${ step . chunk . sourceType } "` )
399340 }
400341
@@ -433,13 +374,7 @@ export async function runMigration(
433374 const s = await getMigrationStatus ( )
434375 if ( s . migration . automaticStepCount > 0 || s . migration . manualStepCount > 0 ) {
435376 try {
436- const res = await runMigration (
437- s . migration . chunks ,
438- s . migration . hash ,
439- inputResults ,
440- false ,
441- chunksLeft - 1
442- )
377+ const res = await runMigration ( s . migration . chunks , s . migration . hash , false , chunksLeft - 1 )
443378 if ( res . migrationCompleted ) {
444379 return res
445380 }
@@ -493,7 +428,6 @@ export async function getMigrationStatus(): Promise<GetMigrationStatusResult> {
493428 migration : {
494429 canDoAutomaticMigration : migration . manualStepCount === 0 ,
495430
496- manualInputs : migration . manualInputs ,
497431 hash : migration . hash ,
498432 chunks : migration . chunks ,
499433
0 commit comments