diff --git a/src/Command/MigrateCommand.php b/src/Command/MigrateCommand.php index 7d96cdc..0ab1533 100644 --- a/src/Command/MigrateCommand.php +++ b/src/Command/MigrateCommand.php @@ -38,6 +38,12 @@ protected function configure() InputOption::VALUE_REQUIRED, 'Table ignore list' ) + ->addOption( + 'progress', + 'p', + InputOption::VALUE_NONE, + 'Display migration progress' + ) ; } @@ -101,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $this->outputString('• Generating migration script ...'); - $migrationScript = $differ->generateMigrationScript($databaseDiff); + $migrationScript = $differ->generateMigrationScript($databaseDiff, (bool) $input->getOption('progress')); $this->outputLine(' '); if ($this->verbose) { diff --git a/src/Differ.php b/src/Differ.php index 620e57e..4f6987b 100644 --- a/src/Differ.php +++ b/src/Differ.php @@ -206,10 +206,11 @@ private function diffForeignKeys(ChangedTable $changedTable) /** * @param DatabaseDiff $databaseDiff + * @param bool $displayProgress * * @return string */ - public function generateMigrationScript(DatabaseDiff $databaseDiff) + public function generateMigrationScript(DatabaseDiff $databaseDiff, $displayProgress = false) { $migrationScript = ''; $migrationScript .= '# Disable Foreign Keys Check' . PHP_EOL; @@ -219,18 +220,33 @@ public function generateMigrationScript(DatabaseDiff $databaseDiff) $migrationScript .= PHP_EOL . '# Deleted Tables' . PHP_EOL; foreach ($databaseDiff->getDeletedTables() as $deletedTable) { $migrationScript .= PHP_EOL . sprintf('-- deleted table `%s`' . PHP_EOL . PHP_EOL, $deletedTable->getName()); + + if ($displayProgress) { + $migrationScript .= sprintf("SELECT 'Dropping table %s';" . PHP_EOL, $deletedTable->getName()); + } + $migrationScript .= sprintf('DROP TABLE `%s`;' . PHP_EOL, $deletedTable->getName()); } $migrationScript .= PHP_EOL . '# Changed Tables' . PHP_EOL; foreach ($databaseDiff->getChangedTables() as $changedTable) { $migrationScript .= PHP_EOL . sprintf('-- changed table `%s`' . PHP_EOL . PHP_EOL, $changedTable->getName()); + + if ($displayProgress) { + $migrationScript .= sprintf("SELECT 'Altering table %s';" . PHP_EOL, $changedTable->getName()); + } + $migrationScript .= $changedTable->generateAlterScript() . PHP_EOL; } $migrationScript .= PHP_EOL . '# New Tables' . PHP_EOL; foreach ($databaseDiff->getNewTables() as $newTable) { $migrationScript .= PHP_EOL . sprintf('-- new table `%s`' . PHP_EOL . PHP_EOL, $newTable->getName()); + + if ($displayProgress) { + $migrationScript .= sprintf("SELECT 'Creating table %s';" . PHP_EOL, $newTable->getName()); + } + $migrationScript .= $newTable->generateCreationScript(true) . PHP_EOL; }