File tree 2 files changed +21
-0
lines changed
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ export default async ({
10
10
migrations : Migration [ ] ;
11
11
migrationStore : MigrationStore ;
12
12
} ) : Promise < void > => {
13
+ if ( migrations . length !== new Set ( migrations . map ( ( migration ) => migration . id ) ) . size ) {
14
+ throw new Error ( 'duplicate migration id' ) ;
15
+ }
16
+
13
17
const appliedMigrations = await migrationStore . getAppliedMigrations ( ) ;
14
18
const migrationsToApply = migrations . filter (
15
19
( migration ) =>
Original file line number Diff line number Diff line change @@ -82,4 +82,21 @@ describe('up', () => {
82
82
expect ( migration1 . up ) . toHaveBeenCalledTimes ( 1 ) ;
83
83
expect ( migration1 . up ) . toHaveBeenCalledWith ( context ) ;
84
84
} ) ;
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
+ } ) ;
85
102
} ) ;
You can’t perform that action at this time.
0 commit comments