Skip to content

Commit

Permalink
Merge branch '3.5.x' into 4.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Sep 10, 2022
2 parents 1f4ca72 + 58beef0 commit b4e4c74
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 147 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,11 @@ The following `Comparator` methods have been marked as internal:

The `diffColumn()` method has been deprecated. Use `diffTable()` instead.

## Marked `ColumnDiff` public properties as internal.

The `$fromColumn` and `$column` properties of the `ColumnDiff` class have been marked as internal. Use the
`getOldColumn()` and `getNewColumn()` methods instead.

## Deprecated `ColumnDiff::$changedProperties` and `::hasChanged()`.

The `ColumnDiff::$changedProperties` property and the `hasChanged()` method have been deprecated. Use one of the
Expand Down
40 changes: 22 additions & 18 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,14 @@ public function getAlterTableSQL(TableDiff $diff): array
continue;
}

$columnArray = array_merge($column->toArray(), [
$columnProperties = array_merge($column->toArray(), [
'comment' => $column->getComment(),
]);

$queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);
$queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL(
$column->getQuotedName($this),
$columnProperties,
);
}

foreach ($diff->removedColumns as $column) {
Expand All @@ -344,24 +347,31 @@ public function getAlterTableSQL(TableDiff $diff): array
continue;
}

$column = $columnDiff->column;
$columnArray = $column->toArray();
$newColumn = $columnDiff->getNewColumn();

$newColumnProperties = array_merge($newColumn->toArray(), [
'comment' => $newColumn->getComment(),
]);

$oldColumn = $columnDiff->getOldColumn();

$columnArray['comment'] = $column->getComment();
$queryParts[] = 'CHANGE ' . $columnDiff->fromColumn->getQuotedName($this) . ' '
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);
$queryParts[] = 'CHANGE ' . $oldColumn->getQuotedName($this) . ' '
. $this->getColumnDeclarationSQL($newColumn->getQuotedName($this), $newColumnProperties);
}

foreach ($diff->renamedColumns as $oldColumnName => $column) {
if ($this->onSchemaAlterTableRenameColumn($oldColumnName, $column, $diff, $columnSql)) {
continue;
}

$oldColumnName = new Identifier($oldColumnName);
$columnArray = $column->toArray();
$columnArray['comment'] = $column->getComment();
$queryParts[] = 'CHANGE ' . $oldColumnName->getQuotedName($this) . ' '
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);
$oldColumnName = new Identifier($oldColumnName);

$columnProperties = array_merge($column->toArray(), [
'comment' => $column->getComment(),
]);

$queryParts[] = 'CHANGE ' . $oldColumnName->getQuotedName($this) . ' '
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnProperties);
}

if (isset($diff->addedIndexes['primary'])) {
Expand Down Expand Up @@ -635,12 +645,6 @@ public function getColumnCharsetDeclarationSQL(string $charset): string
return 'CHARACTER SET ' . $charset;
}

/** @internal The method should be only used from within the {@see AbstractPlatform} class hierarchy. */
public function getColumnCollationDeclarationSQL(string $collation): string
{
return 'COLLATE ' . $this->quoteSingleIdentifier($collation);
}

/** @internal The method should be only used from within the {@see AbstractPlatform} class hierarchy. */
public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ public function getColumnCharsetDeclarationSQL(string $charset): string
*/
public function getColumnCollationDeclarationSQL(string $collation): string
{
return $this->supportsColumnCollation() ? 'COLLATE ' . $collation : '';
return $this->supportsColumnCollation() ? 'COLLATE ' . $this->quoteSingleIdentifier($collation) : '';
}

/**
Expand Down
21 changes: 11 additions & 10 deletions src/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,11 @@ public function getAlterTableSQL(TableDiff $diff): array
}

if ($columnDiff->hasCommentChanged()) {
$newColumn = $columnDiff->getNewColumn();
$commentsSQL[] = $this->getCommentOnColumnSQL(
$diff->getName($this)->getQuotedName($this),
$columnDiff->column->getQuotedName($this),
$columnDiff->column->getComment(),
$newColumn->getQuotedName($this),
$newColumn->getComment(),
);
}

Expand Down Expand Up @@ -409,12 +410,12 @@ private function gatherAlterColumnSQL(
*/
private function getAlterColumnClausesSQL(ColumnDiff $columnDiff): array
{
$column = $columnDiff->column->toArray();
$newColumn = $columnDiff->getNewColumn()->toArray();

$alterClause = 'ALTER COLUMN ' . $columnDiff->column->getQuotedName($this);
$alterClause = 'ALTER COLUMN ' . $columnDiff->getNewColumn()->getQuotedName($this);

if ($column['columnDefinition'] !== null) {
return [$alterClause . ' ' . $column['columnDefinition']];
if ($newColumn['columnDefinition'] !== null) {
return [$alterClause . ' ' . $newColumn['columnDefinition']];
}

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

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

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

if ($defaultClause !== '') {
$clauses[] = $alterClause . ' SET' . $defaultClause;
Expand Down
23 changes: 13 additions & 10 deletions src/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,19 +558,22 @@ public function getAlterTableSQL(TableDiff $diff): array
continue;
}

$column = $columnDiff->column;
$newColumn = $columnDiff->getNewColumn();
$oldColumn = $columnDiff->getOldColumn();

$columnInfo = $column->toArray();
$fromSQL = $this->getColumnDeclarationSQL('', $columnDiff->fromColumn->toArray());
$currentSQL = $this->getColumnDeclarationSQL('', $columnInfo);
$newColumnProperties = $newColumn->toArray();
$oldColumnProperties = $oldColumn->toArray();

if ($currentSQL !== $fromSQL) {
$oldSQL = $this->getColumnDeclarationSQL('', $oldColumnProperties);
$newSQL = $this->getColumnDeclarationSQL('', $newColumnProperties);

if ($newSQL !== $oldSQL) {
if (! $columnDiff->hasNotNullChanged()) {
unset($columnInfo['notnull']);
$currentSQL = $this->getColumnDeclarationSQL('', $columnInfo);
unset($newColumnProperties['notnull']);
$newSQL = $this->getColumnDeclarationSQL('', $newColumnProperties);
}

$modifyColumnSQL[] = $column->getQuotedName($this) . $currentSQL;
$modifyColumnSQL[] = $newColumn->getQuotedName($this) . $newSQL;
}

if (! $columnDiff->hasCommentChanged()) {
Expand All @@ -579,8 +582,8 @@ public function getAlterTableSQL(TableDiff $diff): array

$commentsSQL[] = $this->getCommentOnColumnSQL(
$diff->getName($this)->getQuotedName($this),
$column->getQuotedName($this),
$column->getComment(),
$newColumn->getQuotedName($this),
$newColumn->getComment(),
);
}

Expand Down
54 changes: 24 additions & 30 deletions src/Platforms/PostgreSQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,33 +225,33 @@ public function getAlterTableSQL(TableDiff $diff): array
$commentsSQL = [];
$columnSql = [];

foreach ($diff->addedColumns as $column) {
if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) {
foreach ($diff->addedColumns as $newColumn) {
if ($this->onSchemaAlterTableAddColumn($newColumn, $diff, $columnSql)) {
continue;
}

$query = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray());
$query = 'ADD ' . $this->getColumnDeclarationSQL($newColumn->getQuotedName($this), $newColumn->toArray());
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query;

$comment = $column->getComment();
$comment = $newColumn->getComment();

if ($comment === '') {
continue;
}

$commentsSQL[] = $this->getCommentOnColumnSQL(
$diff->getName($this)->getQuotedName($this),
$column->getQuotedName($this),
$newColumn->getQuotedName($this),
$comment,
);
}

foreach ($diff->removedColumns as $column) {
if ($this->onSchemaAlterTableRemoveColumn($column, $diff, $columnSql)) {
foreach ($diff->removedColumns as $newColumn) {
if ($this->onSchemaAlterTableRemoveColumn($newColumn, $diff, $columnSql)) {
continue;
}

$query = 'DROP ' . $column->getQuotedName($this);
$query = 'DROP ' . $newColumn->getQuotedName($this);
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query;
}

Expand All @@ -260,22 +260,21 @@ public function getAlterTableSQL(TableDiff $diff): array
continue;
}

$fromColumn = $columnDiff->fromColumn;
$oldColumn = $columnDiff->getOldColumn();
$newColumn = $columnDiff->getNewColumn();

$oldColumnName = $fromColumn->getQuotedName($this);

$column = $columnDiff->column;
$oldColumnName = $oldColumn->getQuotedName($this);

if (
$columnDiff->hasTypeChanged()
|| $columnDiff->hasPrecisionChanged()
|| $columnDiff->hasScaleChanged()
|| $columnDiff->hasFixedChanged()
) {
$type = $column->getType();
$type = $newColumn->getType();

// SERIAL/BIGSERIAL are not "real" types and we can't alter a column to that type
$columnDefinition = $column->toArray();
$columnDefinition = $newColumn->toArray();
$columnDefinition['autoincrement'] = false;

// here was a server version check before, but DBAL API does not support this anymore.
Expand All @@ -284,20 +283,21 @@ public function getAlterTableSQL(TableDiff $diff): array
}

if ($columnDiff->hasDefaultChanged()) {
$defaultClause = $column->getDefault() === null
$defaultClause = $newColumn->getDefault() === null
? ' DROP DEFAULT'
: ' SET' . $this->getDefaultValueDeclarationSQL($column->toArray());
$query = 'ALTER ' . $oldColumnName . $defaultClause;
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query;
: ' SET' . $this->getDefaultValueDeclarationSQL($newColumn->toArray());

$query = 'ALTER ' . $oldColumnName . $defaultClause;
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query;
}

if ($columnDiff->hasNotNullChanged()) {
$query = 'ALTER ' . $oldColumnName . ' ' . ($column->getNotnull() ? 'SET' : 'DROP') . ' NOT NULL';
$query = 'ALTER ' . $oldColumnName . ' ' . ($newColumn->getNotnull() ? 'SET' : 'DROP') . ' NOT NULL';
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query;
}

if ($columnDiff->hasAutoIncrementChanged()) {
if ($column->getAutoincrement()) {
if ($newColumn->getAutoincrement()) {
$query = 'ADD GENERATED BY DEFAULT AS IDENTITY';
} else {
$query = 'DROP IDENTITY';
Expand All @@ -307,13 +307,13 @@ public function getAlterTableSQL(TableDiff $diff): array
. ' ALTER ' . $oldColumnName . ' ' . $query;
}

$newComment = $column->getComment();
$oldComment = $columnDiff->fromColumn->getComment();
$newComment = $newColumn->getComment();
$oldComment = $columnDiff->getOldColumn()->getComment();

if ($columnDiff->hasCommentChanged() || $oldComment !== $newComment) {
$commentsSQL[] = $this->getCommentOnColumnSQL(
$diff->getName($this)->getQuotedName($this),
$column->getQuotedName($this),
$newColumn->getQuotedName($this),
$newComment,
);
}
Expand All @@ -323,7 +323,7 @@ public function getAlterTableSQL(TableDiff $diff): array
}

$query = 'ALTER ' . $oldColumnName . ' TYPE '
. $column->getType()->getSQLDeclaration($column->toArray(), $this);
. $newColumn->getType()->getSQLDeclaration($newColumn->toArray(), $this);
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query;
}

Expand Down Expand Up @@ -796,12 +796,6 @@ public function supportsColumnCollation(): bool
return true;
}

/** @internal The method should be only used from within the {@see AbstractPlatform} class hierarchy. */
public function getColumnCollationDeclarationSQL(string $collation): string
{
return 'COLLATE ' . $this->quoteSingleIdentifier($collation);
}

/**
* {@inheritdoc}
*/
Expand Down
Loading

0 comments on commit b4e4c74

Please sign in to comment.