Skip to content

Commit

Permalink
[BUGFIX] Recognize removed columns on PostgreSQL
Browse files Browse the repository at this point in the history
This patch ensures columns of tables which have been removed from
ext_tables.sql definitions are recognized on PostgreSQL so they are
renamed by adding a "zzz_deleted_" prefix.

It also enables the formerly excluded according test for SQLite and
MSSQL which work without necessary changes.

Resolves: #93491
Releases: master, 10.4
Change-Id: Ia892c69a506372f71d066fd707b5c8a27718d2b1
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/67772
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
sgrossberndt authored and lolli42 committed Feb 22, 2021
1 parent 8fe902b commit 154606e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
30 changes: 23 additions & 7 deletions typo3/sysext/core/Classes/Database/Schema/ConnectionMigrator.php
Expand Up @@ -21,6 +21,7 @@
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform as PostgreSqlPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLServer2012Platform as SQLServerPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
Expand Down Expand Up @@ -716,7 +717,7 @@ protected function getUnusedFieldUpdateSuggestions(SchemaDiff $schemaDiff): arra
continue;
}

$isSqlite = $this->tableRunsOnSqlite($index);
$databasePlatform = $this->getDatabasePlatform($index);

// Treat each changed column with a new diff to get a dedicated suggestions
// just for this single column.
Expand All @@ -726,7 +727,7 @@ protected function getUnusedFieldUpdateSuggestions(SchemaDiff $schemaDiff): arra
continue;
}

$changedTables[$index . ':' . $changedColumn->column->getName()] = GeneralUtility::makeInstance(
$renameColumnTableDiff = GeneralUtility::makeInstance(
TableDiff::class,
$changedTable->name,
[],
Expand All @@ -737,7 +738,12 @@ protected function getUnusedFieldUpdateSuggestions(SchemaDiff $schemaDiff): arra
[],
$this->buildQuotedTable($schemaDiff->fromSchema->getTable($changedTable->name))
);
if ($isSqlite) {
if ($databasePlatform === 'postgresql') {
$renameColumnTableDiff->renamedColumns[$oldFieldName] = $changedColumn->column;
}
$changedTables[$index . ':' . $changedColumn->column->getName()] = $renameColumnTableDiff;

if ($databasePlatform === 'sqlite') {
break;
}
}
Expand Down Expand Up @@ -775,7 +781,7 @@ protected function getDropFieldUpdateSuggestions(SchemaDiff $schemaDiff): array
foreach ($schemaDiff->changedTables as $index => $changedTable) {
$fromTable = $this->buildQuotedTable($schemaDiff->fromSchema->getTable($changedTable->name));

$isSqlite = $this->tableRunsOnSqlite($index);
$isSqlite = $this->getDatabasePlatform($index) === 'sqlite';
$addMoreOperations = true;

if (count($changedTable->removedColumns) !== 0) {
Expand Down Expand Up @@ -1330,9 +1336,19 @@ protected function buildQuotedForeignKey(ForeignKeyConstraint $index): ForeignKe
);
}

protected function tableRunsOnSqlite(string $tableName): bool
protected function getDatabasePlatform(string $tableName): string
{
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($tableName);
return $connection->getDatabasePlatform() instanceof SqlitePlatform;
$databasePlatform = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($tableName)->getDatabasePlatform();
if ($databasePlatform instanceof PostgreSqlPlatform) {
return 'postgresql';
}
if ($databasePlatform instanceof SQLServerPlatform) {
return 'mssql';
}
if ($databasePlatform instanceof SqlitePlatform) {
return 'sqlite';
}

return 'mysql';
}
}
Expand Up @@ -203,9 +203,6 @@ public function defaultNullWithoutNotNull()

/**
* @test
* @group not-postgres
* @group not-mssql
* @group not-sqlite
*/
public function renameUnusedField()
{
Expand Down

0 comments on commit 154606e

Please sign in to comment.