import { Migration } from "./types" ; const indexNotMatch = ( migration , index ) => migration . id !== index ; /** Assert migration IDs are consecutive integers */ export function validateMigrationOrdering ( migrations ) { const notMatchingId = migrations . find ( indexNotMatch ) ; if ( notMatchingId ) { throw new Error ( `Found a non-consecutive migration ID on file: '${ notMatchingId . fileName }'` ) ; } } /** Assert hashes match */ export function validateMigrationHashes ( migrations , appliedMigrations ) { const invalidHash = ( migration ) => { const appliedMigration = appliedMigrations [ migration . id ] ; return appliedMigration != null && appliedMigration . hash !== migration . hash ; } ; const invalidHashes = migrations . filter ( invalidHash ) ; if ( invalidHashes . length > 0 ) { const invalidFiles = invalidHashes . map ( ( { fileName } ) => fileName ) ; throw new Error ( `Hashes don't match for migrations '${ invalidFiles }'.
This means that the scripts have changed since it was applied.` ) ; } }