diff --git a/Command/DiffFileCommand.php b/Command/DiffFileCommand.php index d479e76..67a4c8b 100644 --- a/Command/DiffFileCommand.php +++ b/Command/DiffFileCommand.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Version as DbalVersion; use Doctrine\DBAL\Migrations\Provider\OrmSchemaProvider; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; @@ -16,6 +17,13 @@ */ class DiffFileCommand extends \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand { + protected function configure() + { + parent::configure(); + + $this->addOption('check', null, InputOption::VALUE_NONE, 'Check that all migrations have been created.') + } + /** * * @param InputInterface $input @@ -40,6 +48,8 @@ public function execute(InputInterface $input, OutputInterface $output) ->setFilterSchemaAssetsExpression($filterExpr); } + $checkOnly = $input->getOption('check'); + $fromSchema = $this->getLastSchemaDefinition($configuration); $toSchema = $this->getSchemaProvider()->createSchema(); @@ -62,6 +72,11 @@ public function execute(InputInterface $input, OutputInterface $output) return; } + if ($checkOnly) { + $output->writeln('Changes detected in your mapping information!'); + exit(1); + } + $version = date('YmdHis'); $path = $this->generateMigration($configuration, $input, $version, $up, $down); diff --git a/README.md b/README.md index 4cdbad0..75cebc6 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,9 @@ So you only have to run the command before doing a new version of your app. php bin/console doctrine:migrations:diff-file A version file will be generated (if required) and your current schema will be dumped in a file. (in /app/DoctrineMigrations/SchemaVersion) + +You can automatically check that the migrations have been generated using the check option + + php bin/console doctrine:migrations:diff-file --check + +The exit code 1 will be used if a migration should have been generated