File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ export default async ({
1010 migrations : Migration [ ] ;
1111 migrationStore : MigrationStore ;
1212} ) : Promise < void > => {
13+ if ( migrations . length !== new Set ( migrations . map ( ( migration ) => migration . id ) ) . size ) {
14+ throw new Error ( 'duplicate migration id' ) ;
15+ }
16+
1317 const appliedMigrations = await migrationStore . getAppliedMigrations ( ) ;
1418 const migrationsToApply = migrations . filter (
1519 ( migration ) =>
Original file line number Diff line number Diff line change @@ -82,4 +82,21 @@ describe('up', () => {
8282 expect ( migration1 . up ) . toHaveBeenCalledTimes ( 1 ) ;
8383 expect ( migration1 . up ) . toHaveBeenCalledWith ( context ) ;
8484 } ) ;
85+
86+ it ( 'should throw an error when duplicate migration IDs are passed' , async ( ) => {
87+ expect . assertions ( 1 ) ;
88+
89+ // given
90+ const migrations = [ migration1 , migration1 ] ;
91+ MongoMigrationStoreMock . mockImplementationOnce ( ( ) => ( {
92+ init : vi . fn ( ) ,
93+ getAppliedMigrations : vi . fn ( ) . mockReturnValueOnce ( [ ] ) ,
94+ insertMigration : vi . fn ( ) ,
95+ } ) ) ;
96+ const migrationStore = new MongoMigrationStore ( ) ;
97+
98+ // when
99+ // then
100+ await expect ( ( ) => up ( { migrations, migrationStore } ) ) . rejects . toThrowError ( 'duplicate migration id' ) ;
101+ } ) ;
85102} ) ;
You can’t perform that action at this time.
0 commit comments