Merge pull request #25038 from nextcloud/bugfix/noid/install-mysql8-with-php8

Don't try a transaction for the migrator on MySQL
This commit is contained in:
blizzz 2021-01-11 18:07:11 +01:00 committed by GitHub
commit 7cdc7adf59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -32,6 +32,7 @@
namespace OC\DB; namespace OC\DB;
use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\AbstractAsset; use Doctrine\DBAL\Schema\AbstractAsset;
use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Index;
@ -238,15 +239,19 @@ class Migrator {
$schemaDiff = $this->getDiff($targetSchema, $connection); $schemaDiff = $this->getDiff($targetSchema, $connection);
if (!$connection->getDatabasePlatform() instanceof MySQLPlatform) {
$connection->beginTransaction(); $connection->beginTransaction();
}
$sqls = $schemaDiff->toSql($connection->getDatabasePlatform()); $sqls = $schemaDiff->toSql($connection->getDatabasePlatform());
$step = 0; $step = 0;
foreach ($sqls as $sql) { foreach ($sqls as $sql) {
$this->emit($sql, $step++, count($sqls)); $this->emit($sql, $step++, count($sqls));
$connection->query($sql); $connection->query($sql);
} }
if (!$connection->getDatabasePlatform() instanceof MySQLPlatform) {
$connection->commit(); $connection->commit();
} }
}
/** /**
* @param string $sourceName * @param string $sourceName

View File

@ -10,7 +10,9 @@
namespace Test\DB; namespace Test\DB;
use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaConfig; use Doctrine\DBAL\Schema\SchemaConfig;
use OC\DB\SchemaWrapper; use OC\DB\SchemaWrapper;
@ -122,7 +124,11 @@ class MigratorTest extends \Test\TestCase {
} }
private function isSQLite() { 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;
} }
@ -143,7 +149,9 @@ class MigratorTest extends \Test\TestCase {
try { try {
$migrator->migrate($endSchema); $migrator->migrate($endSchema);
} catch (Exception\UniqueConstraintViolationException $e) { } catch (Exception\UniqueConstraintViolationException $e) {
if (!$this->isMySQL()) {
$this->connection->rollBack(); $this->connection->rollBack();
}
throw $e; throw $e;
} }
} }