@@ -38,15 +38,17 @@ protected function configure(): void
3838 $ this ->setDescription ('Migrate the database ' )
3939 ->addOption ('--target ' , '-t ' , InputOption::VALUE_REQUIRED , 'The version number to migrate to ' )
4040 ->addOption ('--date ' , '-d ' , InputOption::VALUE_REQUIRED , 'The date to migrate to ' )
41+ ->addOption ('--count ' , '-k ' , InputOption::VALUE_REQUIRED , 'The number of migrations to run ' )
4142 ->addOption ('--dry-run ' , '-x ' , InputOption::VALUE_NONE , 'Dump query to standard output instead of executing it ' )
4243 ->addOption ('--fake ' , null , InputOption::VALUE_NONE , "Mark any migrations selected as run, but don't actually execute them " )
4344 ->setHelp (
4445 <<<EOT
45- The <info>migrate</info> command runs all available migrations, optionally up to a specific version
46+ The <info>migrate</info> command runs all available migrations, optionally up to a specific version, date, or count.
4647
4748<info>phinx migrate -e development</info>
4849<info>phinx migrate -e development -t 20110103081132</info>
4950<info>phinx migrate -e development -d 20110103</info>
51+ <info>phinx migrate -e development -k 5</info>
5052<info>phinx migrate -e development -v</info>
5153
5254EOT ,
@@ -68,6 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6870 /** @var string|null $environment */
6971 $ environment = $ input ->getOption ('environment ' );
7072 $ date = $ input ->getOption ('date ' );
73+ $ count = $ input ->getOption ('count ' ) !== null ? (int )$ input ->getOption ('count ' ) : null ;
7174 $ fake = (bool )$ input ->getOption ('fake ' );
7275
7376 $ success = $ this ->writeInformationOutput ($ environment , $ output );
@@ -85,7 +88,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8588 try {
8689 // run the migrations
8790 $ start = microtime (true );
88- if ($ date !== null ) {
91+ if ($ count !== null ) {
92+ $ this ->getManager ()->migrateToCount ($ environment , $ count , $ fake );
93+ } elseif ($ date !== null ) {
8994 $ this ->getManager ()->migrateToDateTime ($ environment , new DateTime ($ date ), $ fake );
9095 } else {
9196 $ this ->getManager ()->migrate ($ environment , $ version , $ fake );
0 commit comments