Permalink
Browse files

Merge pull request #290 from fzaninotto/diff_with_migrations

Update diff task to fail when uncommitted migrations are found.
  • Loading branch information...
2 parents 209e34d + 0b34a67 commit e9051d4a170e82220e04f47d8372614023d48252 @willdurand willdurand committed Feb 13, 2012
Showing with 13 additions and 3 deletions.
  1. +8 −3 generator/lib/task/PropelSQLDiffTask.php
  2. +5 −0 generator/lib/util/PropelMigrationManager.php
@@ -104,6 +104,14 @@ public function main()
if (!$connections) {
throw new Exception('You must define database connection settings in a buildtime-conf.xml file to use diff');
}
+ $manager = new PropelMigrationManager();
+ $manager->setConnections($connections);
+ $manager->setMigrationDir($this->getOutputDirectory());
+
+ if ($manager->hasPendingMigrations()) {
+ throw new Exception('Uncommitted migrations have been found ; you should either execute or delete them before rerunning the \'diff\' task');
+ }
+
$totalNbTables = 0;
$ad = new AppData();
foreach ($connections as $name => $params) {
@@ -136,9 +144,6 @@ public function main()
// comparing models
$this->log('Comparing models...');
- $manager = new PropelMigrationManager();
- $manager->setConnections($connections);
- $manager->setMigrationDir($this->getOutputDirectory());
$migrationsUp = array();
$migrationsDown = array();
foreach ($ad->getDatabases() as $database) {
@@ -239,6 +239,11 @@ public function getValidMigrationTimestamps()
return $migrationTimestamps;
}
+ public function hasPendingMigrations()
+ {
+ return array() !== $this->getValidMigrationTimestamps();
+ }
+
public function getAlreadyExecutedMigrationTimestamps()
{
$oldestMigrationTimestamp = $this->getOldestDatabaseVersion();

0 comments on commit e9051d4

Please sign in to comment.