Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(dbal): Move migrator away from deprecated calls
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Oct 6, 2023
commit 919207873ed0f89421d95560cc8134e936028258
20 changes: 9 additions & 11 deletions lib/private/DB/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
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;
Expand Down Expand Up @@ -75,7 +74,7 @@ public function generateChangeScript(Schema $targetSchema) {
$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);
}
Expand All @@ -95,18 +94,18 @@ public function createSchema() {
}
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);
}
Expand All @@ -122,7 +121,7 @@ protected function getDiff(Schema $targetSchema, Connection $connection) {
}
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) {
Expand All @@ -137,9 +136,8 @@ protected function getDiff(Schema $targetSchema, Connection $connection) {
}
}

/** @psalm-suppress InternalMethod */
$comparator = new Comparator();
return $comparator->compare($sourceSchema, $targetSchema);
$comparator = $connection->createSchemaManager()->createComparator();
return $comparator->compareSchemas($sourceSchema, $targetSchema);
}

/**
Expand All @@ -155,7 +153,7 @@ protected function applySchema(Schema $targetSchema, Connection $connection = nu
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));
Expand All @@ -178,7 +176,7 @@ protected function convertStatementToScript($statement) {
}

protected function getFilterExpression() {
return '/^' . preg_quote($this->config->getSystemValueString('dbtableprefix', 'oc_')) . '/';
return '/^' . preg_quote($this->config->getSystemValueString('dbtableprefix', 'oc_'), '/') . '/';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷

}

protected function emit(string $sql, int $step, int $max): void {
Expand Down