import * as sequencesProcessor from './SequencesProcessor' ; import * as migrationStateManager from './MigrationStateManager' ; import processEnum from './EnumProcessor' ; import processNull from './NullProcessor' ; import processDefault from './DefaultProcessor' ; import processIndexAndKey from './IndexAndKeyProcessor' ; import processComments from './CommentsProcessor' ; import processForeignKey from './ForeignKeyProcessor' ; import processViews from './ViewGenerator' ; import Conversion from './Conversion' ; /**
 * Continues migration process after data loading.
 */ export const processConstraints = async ( conversion ) : Promise < Conversion > => { const isTableConstraintsLoaded = await migrationStateManager . get ( conversion , 'per_table_constraints_loaded' ) ; const migrateOnlyData = conversion . shouldMigrateOnlyData ( ) ; if ( ! isTableConstraintsLoaded ) { const promises = conversion . _tablesToMigrate . map ( async ( tableName ) => { await processConstraintsPerTable ( conversion , tableName , migrateOnlyData ) ; } ) ; await Promise . all ( promises ) ; } if ( migrateOnlyData ) { await migrationStateManager . set ( conversion , 'per_table_constraints_loaded' , 'foreign_keys_loaded' , 'views_loaded' ) ; } else { await migrationStateManager . set ( conversion , 'per_table_constraints_loaded' ) ; await processForeignKey ( conversion ) ; await migrationStateManager . set ( conversion , 'foreign_keys_loaded' ) ; await processViews ( conversion ) ; await migrationStateManager . set ( conversion , 'views_loaded' ) ; } return conversion ; } ; /**
 * Processes given table's constraints.
 */ export const processConstraintsPerTable = async ( conversion , tableName , migrateOnlyData ) : Promise < void > => { if ( migrateOnlyData ) { return sequencesProcessor . setSequenceValue ( conversion , tableName ) ; } await processEnum ( conversion , tableName ) ; await processNull ( conversion , tableName ) ; await processDefault ( conversion , tableName ) ; await sequencesProcessor . createSequence ( conversion , tableName ) ; await processIndexAndKey ( conversion , tableName ) ; await processComments ( conversion , tableName ) ; } ;