aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/DB
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2023-07-05 11:42:58 +0200
committerJoas Schilling <coding@schilljs.com>2023-10-06 15:29:26 +0200
commit919207873ed0f89421d95560cc8134e936028258 (patch)
tree1bb77d980d5bade97a3b1c2ce8bae6afa50f9182 /lib/private/DB
parent160298c5569901cc5d33ed74646f28fa41734fed (diff)
downloadnextcloud-server-919207873ed0f89421d95560cc8134e936028258.tar.gz
nextcloud-server-919207873ed0f89421d95560cc8134e936028258.zip
fix(dbal): Move migrator away from deprecated calls
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/DB')
-rw-r--r--lib/private/DB/Migrator.php20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/private/DB/Migrator.php b/lib/private/DB/Migrator.php
index 46be512440a..ad964967f40 100644
--- a/lib/private/DB/Migrator.php
+++ b/lib/private/DB/Migrator.php
@@ -31,7 +31,6 @@ use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\AbstractAsset;
-use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaDiff;
use Doctrine\DBAL\Types\StringType;
@@ -75,7 +74,7 @@ class Migrator {
$schemaDiff = $this->getDiff($targetSchema, $this->connection);
$script = '';
- $sqls = $schemaDiff->toSql($this->connection->getDatabasePlatform());
+ $sqls = $this->connection->getDatabasePlatform()->getAlterSchemaSQL($schemaDiff);
foreach ($sqls as $sql) {
$script .= $this->convertStatementToScript($sql);
}
@@ -95,18 +94,18 @@ class Migrator {
}
return preg_match($filterExpression, $asset) === 1;
});
- return $this->connection->getSchemaManager()->createSchema();
+ return $this->connection->createSchemaManager()->introspectSchema();
}
/**
* @return SchemaDiff
*/
protected function getDiff(Schema $targetSchema, Connection $connection) {
- // adjust varchar columns with a length higher then getVarcharMaxLength to clob
+ // adjust varchar columns with a length higher than getVarcharMaxLength to clob
foreach ($targetSchema->getTables() as $table) {
foreach ($table->getColumns() as $column) {
if ($column->getType() instanceof StringType) {
- if ($column->getLength() > $connection->getDatabasePlatform()->getVarcharMaxLength()) {
+ if ($column->getLength() > 4000) {
$column->setType(Type::getType('text'));
$column->setLength(null);
}
@@ -122,7 +121,7 @@ class Migrator {
}
return preg_match($filterExpression, $asset) === 1;
});
- $sourceSchema = $connection->getSchemaManager()->createSchema();
+ $sourceSchema = $connection->createSchemaManager()->introspectSchema();
// remove tables we don't know about
foreach ($sourceSchema->getTables() as $table) {
@@ -137,9 +136,8 @@ class Migrator {
}
}
- /** @psalm-suppress InternalMethod */
- $comparator = new Comparator();
- return $comparator->compare($sourceSchema, $targetSchema);
+ $comparator = $connection->createSchemaManager()->createComparator();
+ return $comparator->compareSchemas($sourceSchema, $targetSchema);
}
/**
@@ -155,7 +153,7 @@ class Migrator {
if (!$connection->getDatabasePlatform() instanceof MySQLPlatform) {
$connection->beginTransaction();
}
- $sqls = $schemaDiff->toSql($connection->getDatabasePlatform());
+ $sqls = $connection->getDatabasePlatform()->getAlterSchemaSQL($schemaDiff);
$step = 0;
foreach ($sqls as $sql) {
$this->emit($sql, $step++, count($sqls));
@@ -178,7 +176,7 @@ class Migrator {
}
protected function getFilterExpression() {
- return '/^' . preg_quote($this->config->getSystemValueString('dbtableprefix', 'oc_')) . '/';
+ return '/^' . preg_quote($this->config->getSystemValueString('dbtableprefix', 'oc_'), '/') . '/';
}
protected function emit(string $sql, int $step, int $max): void {