Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TableDiff deprecation points to wrong method #6273

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
36 changes: 20 additions & 16 deletions src/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ public function getAlterTableSQL(TableDiff $diff)
$tableNameSQL = ($diff->getOldTable() ?? $diff->getName($this))->getQuotedName($this);

$queryParts = [];
$needsReorg = false;

foreach ($diff->getAddedColumns() as $column) {
if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) {
continue;
Expand All @@ -610,7 +612,8 @@ public function getAlterTableSQL(TableDiff $diff)

$queryParts[] = $queryPart;

$comment = $this->getColumnComment($column);
$comment = $this->getColumnComment($column);
$needsReorg = true;

if ($comment === null || $comment === '') {
continue;
Expand All @@ -623,7 +626,6 @@ public function getAlterTableSQL(TableDiff $diff)
);
}

$needsReorg = false;
foreach ($diff->getDroppedColumns() as $column) {
if ($this->onSchemaAlterTableRemoveColumn($column, $diff, $columnSql)) {
continue;
Expand Down Expand Up @@ -660,13 +662,8 @@ public function getAlterTableSQL(TableDiff $diff)
$columnDiff,
$sql,
$queryParts,
$needsReorg,
);

if (empty($columnDiff->changedProperties)) {
continue;
}

$needsReorg = true;
}

$tableSql = [];
Expand Down Expand Up @@ -732,11 +729,12 @@ private function gatherAlterColumnSQL(
string $table,
ColumnDiff $columnDiff,
array &$sql,
array &$queryParts
array &$queryParts,
bool &$needsReorg
): void {
$alterColumnClauses = $this->getAlterColumnClausesSQL($columnDiff);
$alterColumnClauses = $this->getAlterColumnClausesSQL($columnDiff, $needsReorg);

if (empty($alterColumnClauses)) {
if (count($alterColumnClauses) < 1) {
return;
}

Expand All @@ -760,7 +758,7 @@ private function gatherAlterColumnSQL(
*
* @return string[]
*/
private function getAlterColumnClausesSQL(ColumnDiff $columnDiff): array
private function getAlterColumnClausesSQL(ColumnDiff $columnDiff, bool &$needsReorg): array
{
$newColumn = $columnDiff->getNewColumn()->toArray();

Expand All @@ -770,6 +768,8 @@ private function getAlterColumnClausesSQL(ColumnDiff $columnDiff): array
$alterClause = 'ALTER COLUMN ' . $newName;

if ($newColumn['columnDefinition'] !== null) {
$needsReorg = true;

return [$alterClause . ' ' . $newColumn['columnDefinition']];
}

Expand All @@ -786,22 +786,26 @@ private function getAlterColumnClausesSQL(ColumnDiff $columnDiff): array
$columnDiff->hasScaleChanged() ||
$columnDiff->hasFixedChanged()
) {
$clauses[] = $alterClause . ' SET DATA TYPE ' . $newColumn['type']->getSQLDeclaration($newColumn, $this);
$needsReorg = true;
$clauses[] = $alterClause . ' SET DATA TYPE ' . $newColumn['type']->getSQLDeclaration($newColumn, $this);
}

if ($columnDiff->hasNotNullChanged()) {
$clauses[] = $newColumn['notnull'] ? $alterClause . ' SET NOT NULL' : $alterClause . ' DROP NOT NULL';
$needsReorg = true;
$clauses[] = $newColumn['notnull'] ? $alterClause . ' SET NOT NULL' : $alterClause . ' DROP NOT NULL';
}

if ($columnDiff->hasDefaultChanged()) {
if (isset($newColumn['default'])) {
$defaultClause = $this->getDefaultValueDeclarationSQL($newColumn);

if ($defaultClause !== '') {
$clauses[] = $alterClause . ' SET' . $defaultClause;
$needsReorg = true;
$clauses[] = $alterClause . ' SET' . $defaultClause;
}
} else {
$clauses[] = $alterClause . ' DROP DEFAULT';
$needsReorg = true;
$clauses[] = $alterClause . ' DROP DEFAULT';
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Schema/TableDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public function getModifiedColumns(): array
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6080',
'%s is deprecated, use `getModifiedColumns()` instead.',
'%s is deprecated, use `getChangedColumns()` instead.',
__METHOD__,
);

Expand All @@ -301,7 +301,7 @@ public function getDroppedColumns(): array
}

/**
* @deprecated Use {@see getModifiedColumns()} instead.
* @deprecated Use {@see getChangedColumns()} instead.
*
* @return array<string,Column>
*/
Expand All @@ -310,7 +310,7 @@ public function getRenamedColumns(): array
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6080',
'%s is deprecated, you should use `getModifiedColumns()` instead.',
'%s is deprecated, you should use `getChangedColumns()` instead.',
__METHOD__,
);
$renamed = [];
Expand Down
8 changes: 6 additions & 2 deletions tests/Platforms/DB2PlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,8 @@ protected function getCommentOnColumnSQL(): array
public function testGeneratesAlterColumnSQL(
string $changedProperty,
Column $column,
?string $expectedSQLClause = null
?string $expectedSQLClause = null,
bool $shouldReorg = true
): void {
$tableDiff = new TableDiff('foo');
$tableDiff->fromTable = new Table('foo');
Expand All @@ -554,7 +555,9 @@ public function testGeneratesAlterColumnSQL(
$expectedSQL[] = 'ALTER TABLE foo ALTER COLUMN bar ' . $expectedSQLClause;
}

$expectedSQL[] = "CALL SYSPROC.ADMIN_CMD ('REORG TABLE foo')";
if ($shouldReorg) {
$expectedSQL[] = "CALL SYSPROC.ADMIN_CMD ('REORG TABLE foo')";
}

self::assertSame($expectedSQL, $this->platform->getAlterTableSQL($tableDiff));
}
Expand Down Expand Up @@ -612,6 +615,7 @@ public static function getGeneratesAlterColumnSQL(): iterable
'default',
new Column('bar', Type::getType(Types::INTEGER), ['autoincrement' => true, 'default' => 666]),
null,
false,
],
[
'default',
Expand Down