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
@@ -92,7 +87,6 @@ export interface PreparedMigration {
9287 automaticStepCount : number
9388 manualStepCount : number
9489 ignoredStepCount : number
95- manualInputs : MigrationStepInput [ ]
9690 partialMigration : boolean
9791}
9892export async function prepareMigration ( returnAllChunks ?: boolean ) : Promise < PreparedMigration > {
@@ -128,7 +122,6 @@ export async function prepareMigration(returnAllChunks?: boolean): Promise<Prepa
128122 validate : step . validate . bind ( step ) ,
129123 canBeRunAutomatically : step . canBeRunAutomatically ,
130124 migrate : step . migrate ?. bind ( step ) ,
131- input : step . input ,
132125 dependOnResultFrom : step . dependOnResultFrom ,
133126 version : step . version ,
134127 _version : parseVersion ( step . version ) ,
@@ -165,9 +158,6 @@ export async function prepareMigration(returnAllChunks?: boolean): Promise<Prepa
165158 const ignoredSteps : { [ id : string ] : true } = { }
166159 let includesCoreStep = false
167160 for ( const step of allMigrationSteps ) {
168- if ( ! step . canBeRunAutomatically && ( ! step . input || ( Array . isArray ( step . input ) && ! step . input . length ) ) )
169- throw new Meteor . Error ( 500 , `MigrationStep "${ step . id } " is manual, but no input is provided` )
170-
171161 if ( step . chunk . sourceType !== MigrationStepType . CORE && includesCoreStep ) {
172162 // stop here as core migrations need to be run before anything else can
173163 partialMigration = true
@@ -230,39 +220,12 @@ export async function prepareMigration(returnAllChunks?: boolean): Promise<Prepa
230220 // check if there are any manual steps:
231221 // (this makes an automatic migration impossible)
232222
233- const manualInputs : Array < MigrationStepInput > = [ ]
234223 const stepsHash : Array < string > = [ ]
235224 for ( const step of Object . values < MigrationStepInternal > ( migrationSteps ) ) {
236225 stepsHash . push ( step . id )
237226 step . chunk . _steps . push ( step . id )
238227 if ( ! step . canBeRunAutomatically ) {
239228 manualStepCount ++
240-
241- if ( step . input ) {
242- let input : Array < MigrationStepInput > = [ ]
243- if ( Array . isArray ( step . input ) ) {
244- input = clone ( step . input )
245- } else if ( typeof step . input === 'function' ) {
246- if ( step . chunk . sourceType === MigrationStepType . CORE ) {
247- const inputFunction = step . input as InputFunctionCore
248- input = inputFunction ( )
249- } else throw new Meteor . Error ( 500 , `Unknown step.chunk.sourceType "${ step . chunk . sourceType } "` )
250- }
251- if ( input . length ) {
252- for ( const i of input ) {
253- if ( i . label && typeof step . _validateResult === 'string' ) {
254- i . label = ( i . label + '' ) . replace ( / \$ v a l i d a t i o n / g, step . _validateResult )
255- }
256- if ( i . description && typeof step . _validateResult === 'string' ) {
257- i . description = ( i . description + '' ) . replace ( / \$ v a l i d a t i o n / g, step . _validateResult )
258- }
259- manualInputs . push ( {
260- ...i ,
261- stepId : step . id ,
262- } )
263- }
264- }
265- }
266229 } else {
267230 automaticStepCount ++
268231 }
@@ -288,15 +251,13 @@ export async function prepareMigration(returnAllChunks?: boolean): Promise<Prepa
288251 automaticStepCount : automaticStepCount ,
289252 manualStepCount : manualStepCount ,
290253 ignoredStepCount : ignoredStepCount ,
291- manualInputs : manualInputs ,
292254 partialMigration : partialMigration ,
293255 }
294256}
295257
296258export async function runMigration (
297259 chunks : Array < MigrationChunk > ,
298260 hash : string ,
299- inputResults : Array < MigrationStepInputResult > ,
300261 isFirstOfPartialMigrations = true ,
301262 chunksLeft = 20
302263) : Promise < RunMigrationResult > {
@@ -310,19 +271,9 @@ export async function runMigration(
310271 // Verify the input:
311272 const migration = await prepareMigration ( true )
312273
313- const manualInputsWithUserPrompt = migration . manualInputs . filter ( ( manualInput ) => {
314- return ! ! ( manualInput . stepId && manualInput . attribute )
315- } )
316274 if ( migration . hash !== hash )
317275 throw new Meteor . Error ( 500 , `Migration input hash differ from expected: "${ hash } ", "${ migration . hash } "` )
318276
319- if ( manualInputsWithUserPrompt . length !== inputResults . length ) {
320- throw new Meteor . Error (
321- 500 ,
322- `Migration manualInput lengths differ from expected: "${ inputResults . length } ", "${ migration . manualInputs . length } "`
323- )
324- }
325-
326277 // Check that chunks match:
327278 let unmatchedChunk = migration . chunks . find ( ( migrationChunk ) => {
328279 return ! chunks . find ( ( chunk ) => {
@@ -373,26 +324,16 @@ export async function runMigration(
373324 `Migration: ${ migration . automaticStepCount } automatic and ${ migration . manualStepCount } manual steps (${ migration . ignoredStepCount } ignored).`
374325 )
375326
376- logger . debug ( inputResults )
377-
378327 for ( const step of migration . steps ) {
379328 try {
380- // Prepare input from user
381- const stepInput : MigrationStepInputFilteredResult = { }
382- for ( const ir of inputResults ) {
383- if ( ir . stepId === step . id ) {
384- stepInput [ ir . attribute ] = ir . value
385- }
386- }
387-
388329 // Run the migration script
389330
390331 if ( step . migrate !== undefined ) {
391332 logger . info ( `Running migration step "${ step . id } "` )
392333
393334 if ( step . chunk . sourceType === MigrationStepType . CORE ) {
394335 const migration = step . migrate as MigrateFunctionCore
395- await migration ( stepInput )
336+ await migration ( )
396337 } else throw new Meteor . Error ( 500 , `Unknown step.chunk.sourceType "${ step . chunk . sourceType } "` )
397338 }
398339
@@ -431,13 +372,7 @@ export async function runMigration(
431372 const s = await getMigrationStatus ( )
432373 if ( s . migration . automaticStepCount > 0 || s . migration . manualStepCount > 0 ) {
433374 try {
434- const res = await runMigration (
435- s . migration . chunks ,
436- s . migration . hash ,
437- inputResults ,
438- false ,
439- chunksLeft - 1
440- )
375+ const res = await runMigration ( s . migration . chunks , s . migration . hash , false , chunksLeft - 1 )
441376 if ( res . migrationCompleted ) {
442377 return res
443378 }
@@ -491,7 +426,6 @@ export async function getMigrationStatus(): Promise<GetMigrationStatusResult> {
491426 migration : {
492427 canDoAutomaticMigration : migration . manualStepCount === 0 ,
493428
494- manualInputs : migration . manualInputs ,
495429 hash : migration . hash ,
496430 chunks : migration . chunks ,
497431
0 commit comments