@@ -63,6 +63,8 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
6363 '' ,
6464 '<info>migrations status -c secondary</info> ' ,
6565 '<info>migrations status -c secondary -f json</info> ' ,
66+ '<info>migrations status --cleanup</info> ' ,
67+ 'Remove *MISSING* migrations from the phinxlog table ' ,
6668 ])->addOption ('plugin ' , [
6769 'short ' => 'p ' ,
6870 'help ' => 'The plugin to run migrations for ' ,
@@ -79,6 +81,10 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar
7981 'help ' => 'The output format: text or json. Defaults to text. ' ,
8082 'choices ' => ['text ' , 'json ' ],
8183 'default ' => 'text ' ,
84+ ])->addOption ('cleanup ' , [
85+ 'help ' => 'Remove MISSING migrations from the phinxlog table ' ,
86+ 'boolean ' => true ,
87+ 'default ' => false ,
8288 ]);
8389
8490 return $ parser ;
@@ -95,6 +101,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
95101 {
96102 /** @var string|null $format */
97103 $ format = $ args ->getOption ('format ' );
104+ $ clean = $ args ->getOption ('cleanup ' );
98105
99106 $ factory = new ManagerFactory ([
100107 'plugin ' => $ args ->getOption ('plugin ' ),
@@ -103,6 +110,18 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
103110 'dry-run ' => $ args ->getOption ('dry-run ' ),
104111 ]);
105112 $ manager = $ factory ->createManager ($ io );
113+
114+ if ($ clean ) {
115+ $ removed = $ manager ->cleanupMissingMigrations ();
116+ if ($ removed === 0 ) {
117+ $ io ->out ('<info>No missing migrations to clean up.</info> ' );
118+ } else {
119+ $ io ->out (sprintf ('<info>Removed %d missing migration(s) from migration log.</info> ' , $ removed ));
120+ }
121+
122+ return Command::CODE_SUCCESS ;
123+ }
124+
106125 $ migrations = $ manager ->printStatus ($ format );
107126
108127 switch ($ format ) {
0 commit comments