Skip to content

Commit 5c3316b

Browse files
Merge pull request #9 from A5sys/ci-check
option to check only is all migrations have been generated
2 parents 8a708b6 + 9d82a76 commit 5c3316b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Command/DiffFileCommand.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Doctrine\DBAL\Version as DbalVersion;
77
use Doctrine\DBAL\Migrations\Provider\OrmSchemaProvider;
88
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Input\InputOption;
910
use Symfony\Component\Console\Output\OutputInterface;
1011
use Symfony\Component\Filesystem\Filesystem;
1112
use Symfony\Component\Finder\Finder;
@@ -16,6 +17,13 @@
1617
*/
1718
class DiffFileCommand extends \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand
1819
{
20+
protected function configure()
21+
{
22+
parent::configure();
23+
24+
$this->addOption('check', null, InputOption::VALUE_NONE, 'Check that all migrations have been created.')
25+
}
26+
1927
/**
2028
*
2129
* @param InputInterface $input
@@ -40,6 +48,8 @@ public function execute(InputInterface $input, OutputInterface $output)
4048
->setFilterSchemaAssetsExpression($filterExpr);
4149
}
4250

51+
$checkOnly = $input->getOption('check');
52+
4353
$fromSchema = $this->getLastSchemaDefinition($configuration);
4454
$toSchema = $this->getSchemaProvider()->createSchema();
4555

@@ -62,6 +72,11 @@ public function execute(InputInterface $input, OutputInterface $output)
6272
return;
6373
}
6474

75+
if ($checkOnly) {
76+
$output->writeln('<error>Changes detected in your mapping information!</error>');
77+
exit(1);
78+
}
79+
6580
$version = date('YmdHis');
6681
$path = $this->generateMigration($configuration, $input, $version, $up, $down);
6782

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ So you only have to run the command before doing a new version of your app.
1616
php bin/console doctrine:migrations:diff-file
1717

1818
A version file will be generated (if required) and your current schema will be dumped in a file. (in /app/DoctrineMigrations/SchemaVersion)
19+
20+
You can automatically check that the migrations have been generated using the check option
21+
22+
php bin/console doctrine:migrations:diff-file --check
23+
24+
The exit code 1 will be used if a migration should have been generated

0 commit comments

Comments
 (0)