mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
fix(dbal): Move migrator away from deprecated calls
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
160298c556
commit
919207873e
1 changed files with 9 additions and 11 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue