@@ -55,8 +55,11 @@ describe.each([[undefined], ["My Commit Message"]])(
5555 const {
5656 MIGRATION_1_TEXT ,
5757 MIGRATION_1_COMMITTED ,
58+ MIGRATION_INCLUDE_TEXT ,
59+ MIGRATION_INCLUDE_COMMITTED ,
5860 MIGRATION_MULTIFILE_COMMITTED ,
5961 MIGRATION_MULTIFILE_FILES ,
62+ MIGRATION_INCLUDED_FIXTURE ,
6063 } = makeMigrations ( commitMessage ) ;
6164
6265 it ( "rolls back migration" , async ( ) => {
@@ -88,6 +91,36 @@ describe.each([[undefined], ["My Commit Message"]])(
8891 ) . toEqual ( MIGRATION_1_COMMITTED ) ;
8992 } ) ;
9093
94+ it ( "rolls back a migration that has included another file" , async ( ) => {
95+ mockFs ( {
96+ [ `migrations/committed/000001${ commitMessageSlug } .sql` ] :
97+ MIGRATION_INCLUDE_COMMITTED ,
98+ "migrations/current.sql" : "-- JUST A COMMENT\n" ,
99+ "migrations/fixtures/foo.sql" : MIGRATION_INCLUDED_FIXTURE ,
100+ } ) ;
101+ await migrate ( settings ) ;
102+ await uncommit ( settings ) ;
103+
104+ await expect (
105+ fsp . stat ( "migrations/committed/000001.sql" ) ,
106+ ) . rejects . toMatchObject ( {
107+ code : "ENOENT" ,
108+ } ) ;
109+ expect ( await fsp . readFile ( "migrations/current.sql" , "utf8" ) ) . toEqual (
110+ ( commitMessage ? `--! Message: ${ commitMessage } \n\n` : "" ) +
111+ MIGRATION_INCLUDE_TEXT . trim ( ) +
112+ "\n" ,
113+ ) ;
114+
115+ await commit ( settings ) ;
116+ expect (
117+ await fsp . readFile (
118+ `migrations/committed/000001${ commitMessageSlug } .sql` ,
119+ "utf8" ,
120+ ) ,
121+ ) . toEqual ( MIGRATION_INCLUDE_COMMITTED ) ;
122+ } ) ;
123+
91124 it ( "rolls back multifile migration" , async ( ) => {
92125 mockFs ( {
93126 [ `migrations/committed/000001${ commitMessageSlug } .sql` ] :
@@ -139,5 +172,54 @@ describe.each([[undefined], ["My Commit Message"]])(
139172 ) ,
140173 ) . toEqual ( MIGRATION_MULTIFILE_COMMITTED ) ;
141174 } ) ;
175+
176+ it ( "supports the same fixture twice" , async ( ) => {
177+ const current = `\
178+ --!include fixture2.sql
179+ select 22;
180+ --!include fixture2.sql
181+ ` ;
182+ mockFs ( {
183+ "migrations/fixtures/fixture1.sql" : "select 'fixture1';" ,
184+ "migrations/fixtures/fixture2.sql" :
185+ "select 1;\n--!include fixture1.sql\nselect 2;" ,
186+ [ `migrations/committed/000001${ commitMessageSlug } .sql` ] :
187+ MIGRATION_1_COMMITTED ,
188+ [ `migrations/committed/000002${ commitMessageSlug } .sql` ] :
189+ MIGRATION_MULTIFILE_COMMITTED ,
190+ "migrations/current/1.sql" : current ,
191+ } ) ;
192+ await migrate ( settings ) ;
193+ await commit ( settings , commitMessage ) ;
194+ expect (
195+ await fsp . readFile (
196+ `migrations/committed/000003${ commitMessageSlug } .sql` ,
197+ "utf8" ,
198+ ) ,
199+ ) . toContain (
200+ `\
201+ --! Included fixture2.sql
202+ select 1;
203+ --! Included fixture1.sql
204+ select 'fixture1';
205+ --! EndIncluded fixture1.sql
206+ select 2;
207+ --! EndIncluded fixture2.sql
208+ select 22;
209+ --! Included fixture2.sql
210+ select 1;
211+ --! Included fixture1.sql
212+ select 'fixture1';
213+ --! EndIncluded fixture1.sql
214+ select 2;
215+ --! EndIncluded fixture2.sql
216+ ` ,
217+ ) ;
218+ await uncommit ( settings ) ;
219+
220+ expect ( await fsp . readFile ( `migrations/current/1.sql` , "utf8" ) ) . toEqual (
221+ ( commitMessage ? `--! Message: ${ commitMessage } \n\n` : "" ) + current ,
222+ ) ;
223+ } ) ;
142224 } ,
143225) ;
0 commit comments