Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/private/DB/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
namespace OC\DB;

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\AbstractAsset;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Index;
Expand Down Expand Up @@ -238,14 +239,18 @@ protected function applySchema(Schema $targetSchema, \Doctrine\DBAL\Connection $

$schemaDiff = $this->getDiff($targetSchema, $connection);

$connection->beginTransaction();
if (!$connection->getDatabasePlatform() instanceof MySQLPlatform) {
$connection->beginTransaction();
}
$sqls = $schemaDiff->toSql($connection->getDatabasePlatform());
$step = 0;
foreach ($sqls as $sql) {
$this->emit($sql, $step++, count($sqls));
$connection->query($sql);
}
$connection->commit();
if (!$connection->getDatabasePlatform() instanceof MySQLPlatform) {
$connection->commit();
}
}

/**
Expand Down
12 changes: 10 additions & 2 deletions tests/lib/DB/MigratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
namespace Test\DB;

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaConfig;
use OC\DB\SchemaWrapper;
Expand Down Expand Up @@ -122,7 +124,11 @@ private function getSchemaConfig() {
}

private function isSQLite() {
return $this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver;
return $this->connection->getDatabasePlatform() instanceof SqlitePlatform;
}

private function isMySQL() {
return $this->connection->getDatabasePlatform() instanceof MySQLPlatform;
}


Expand All @@ -143,7 +149,9 @@ public function testDuplicateKeyUpgrade() {
try {
$migrator->migrate($endSchema);
} catch (Exception\UniqueConstraintViolationException $e) {
$this->connection->rollBack();
if (!$this->isMySQL()) {
$this->connection->rollBack();
}
throw $e;
}
}
Expand Down