@@ -247,6 +247,49 @@ public function testExecuteWithResetWithNumber():void {
247247 }
248248 }
249249
250+ public function testExecuteWithForceResetsSqliteDatabaseAndRerunsFromMigrationOne ():void {
251+ $ project = $ this ->createProjectDir ();
252+ $ sqlitePath = str_replace ("\\" , "/ " , $ project . DIRECTORY_SEPARATOR . "cli-test.db " );
253+ $ this ->writeConfigIni ($ project , $ sqlitePath );
254+ $ this ->createMigrations ($ project , 2 );
255+
256+ $ cwdBackup = getcwd ();
257+ chdir ($ project );
258+ try {
259+ $ cmd = new ExecuteCommand ();
260+ $ initialStreams = $ this ->makeStreamFiles ();
261+ $ cmd ->setStream ($ initialStreams ["stream " ]);
262+ $ cmd ->run (new ArgumentValueList ());
263+
264+ $ settings = new Settings ($ project . DIRECTORY_SEPARATOR . "query " , Settings::DRIVER_SQLITE , $ sqlitePath );
265+ $ db = new Database ($ settings );
266+ $ db ->executeSql ("insert into `test` (`id`, `name`, `new_column_2`) values (1, 'before-force', 'value') " );
267+ $ rowCountBeforeForce = $ db ->executeSql ("select count(*) as c from `test` " )->fetch ()?->getInt("c " );
268+ self ::assertSame (1 , $ rowCountBeforeForce );
269+
270+ unset($ db );
271+
272+ $ forceStreams = $ this ->makeStreamFiles ();
273+ $ cmd ->setStream ($ forceStreams ["stream " ]);
274+ $ args = new ArgumentValueList ();
275+ $ args ->set ("force " );
276+ $ cmd ->run ($ args );
277+
278+ list ("out " => $ out ) = $ this ->readFromFiles ($ forceStreams ["out " ], $ forceStreams ["err " ]);
279+ self ::assertStringContainsString ("Migration 1: " , $ out );
280+ self ::assertStringContainsString ("2 migrations were completed successfully. " , $ out );
281+
282+ $ dbAfterForce = new Database ($ settings );
283+ $ rowCountAfterForce = $ dbAfterForce ->executeSql ("select count(*) as c from `test` " )->fetch ()?->getInt("c " );
284+ self ::assertSame (0 , $ rowCountAfterForce );
285+ $ migrationCount = $ dbAfterForce ->executeSql ("select count(*) as c from `_migration` " )->fetch ()?->getInt("c " );
286+ self ::assertSame (2 , $ migrationCount );
287+ }
288+ finally {
289+ chdir ($ cwdBackup );
290+ }
291+ }
292+
250293 public function testOptionalParameterListContainsCliOverrides ():void {
251294 $ command = new ExecuteCommand ();
252295 $ parameterNames = array_map (
0 commit comments