Skip to content

Commit

Permalink
fix: Database Migration does set current version in DB FriendsOfSymfo…
Browse files Browse the repository at this point in the history
  • Loading branch information
alquerci committed Jul 3, 2024
1 parent f47a790 commit 179df9e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,4 +559,4 @@ protected function _createMigrationTable()
return false;
}
}
}
}
23 changes: 20 additions & 3 deletions tests/DoctrineTest/Doctrine_UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ public function init()

if (count($e) > 3) {
$driver = $e[2];
switch($e[2]) {

switch($driver) {
case 'Mysql':
case 'Mssql':
case 'Oracle':
case 'Pgsql':
case 'Sqlite':
$this->driverName = $e[2];
$this->driverName = $driver;
break;
}
}
Expand Down Expand Up @@ -227,7 +228,14 @@ public function prepareTables() {

}
}
$this->conn->export->exportClasses($this->tables);

foreach ($this->tables as $table) {
try {
$this->conn->export->exportClasses(array($table));
} catch (Doctrine_Export_Exception $e) {
}
}

$this->objTable = $this->connection->getTable('User');
}
public function prepareData()
Expand Down Expand Up @@ -307,6 +315,13 @@ public function getDeclaration($type)
return $this->dataDict->getPortableDeclaration(array('type' => $type, 'name' => 'colname', 'length' => 1, 'fixed' => true));
}

protected function openAndBindMysqlConnection()
{
$this->dbh = new PDO(getenv('MYSQL_DSN'));

$this->conn = $this->connection = $this->openAdditionalConnection($this->dbh);
}

protected function openAdditionalConnection($adapter = null, $name = null)
{
$connection = $this->manager->openConnection($adapter, $name);
Expand All @@ -321,5 +336,7 @@ private function closeAdditionalConnections()
foreach ($this->additionalConnections as $connection) {
$this->manager->closeConnection($connection);
}

$this->conn = $this->connection = Doctrine_Manager::getInstance()->getCurrentConnection();
}
}
31 changes: 31 additions & 0 deletions tests/MigrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,35 @@ public function testMigrationClassNameInflected()
$this->assertTrue($code);
}
}

public function test_afterSuccessfullMigration_willSetMigratedVersionAsCurrentVersionInMysqlDB()
{
$this->openAndBindMysqlConnection();

parent::prepareTables();

$migration = new Doctrine_Migration('migration_classes');
$migration->setCurrentVersion(3);

$migration->migrate(4);
$this->assertEqual(4, $migration->getCurrentVersion());
}

public function test_afterFailedMigration_willKeepCurrentVersionInMysqlDB()
{
$this->openAndBindMysqlConnection();

parent::prepareTables();

$migration = new Doctrine_Migration('migration_classes');
$migration->setCurrentVersion(0);

try {
$migration->migrate(1);

$this->fail('migration must fail');
} catch (Doctrine_Migration_Exception $e) {
$this->assertEqual(0, $migration->getCurrentVersion());
}
}
}

0 comments on commit 179df9e

Please sign in to comment.