]> source.dussan.org Git - nextcloud-server.git/commitdiff
Don't try a transaction for the migrator on MySQL
authorJoas Schilling <coding@schilljs.com>
Fri, 8 Jan 2021 15:25:40 +0000 (16:25 +0100)
committerJoas Schilling <coding@schilljs.com>
Fri, 8 Jan 2021 15:25:40 +0000 (16:25 +0100)
As per https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html
CREATE TABLE statements automatically commit always. The only reason
this worked in the past was that PHPs PDO connection didn't check the
actual state on commit, but only checked their internal state.
But in PHP8 this was fixed:
https://github.com/php/php-src/blob/PHP-8.0/UPGRADING#L446-L450
So now commit() fails because the internal PDO connection implicitly
commited already.

Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/DB/Migrator.php

index f62735ea6b2cfa099e10ab6629b2afd87f8cbc70..e50927f620bf162f3851c81ed98f7bd004726c59 100644 (file)
@@ -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;
@@ -238,14 +239,18 @@ class Migrator {
 
                $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();
+               }
        }
 
        /**