Skip to content

Commit 95cf2da

Browse files
committed
Mark ColumnDiff public properties as internal
1 parent e5e8607 commit 95cf2da

File tree

7 files changed

+167
-133
lines changed

7 files changed

+167
-133
lines changed

src/Platforms/AbstractMySQLPlatform.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -618,11 +618,14 @@ public function getAlterTableSQL(TableDiff $diff)
618618
continue;
619619
}
620620

621-
$columnArray = array_merge($column->toArray(), [
621+
$columnProperties = array_merge($column->toArray(), [
622622
'comment' => $this->getColumnComment($column),
623623
]);
624624

625-
$queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);
625+
$queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL(
626+
$column->getQuotedName($this),
627+
$columnProperties,
628+
);
626629
}
627630

628631
foreach ($diff->removedColumns as $column) {
@@ -638,31 +641,31 @@ public function getAlterTableSQL(TableDiff $diff)
638641
continue;
639642
}
640643

641-
$column = $columnDiff->column;
642-
$columnArray = $column->toArray();
644+
$newColumn = $columnDiff->getNewColumn();
643645

644-
$columnArray['comment'] = $this->getColumnComment($column);
646+
$newColumnProperties = array_merge($newColumn->toArray(), [
647+
'comment' => $this->getColumnComment($newColumn),
648+
]);
645649

646-
if ($columnDiff->fromColumn !== null) {
647-
$fromColumn = $columnDiff->fromColumn;
648-
} else {
649-
$fromColumn = $columnDiff->getOldColumnName();
650-
}
650+
$oldColumn = $columnDiff->getOldColumn() ?? $columnDiff->getOldColumnName();
651651

652-
$queryParts[] = 'CHANGE ' . $fromColumn->getQuotedName($this) . ' '
653-
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);
652+
$queryParts[] = 'CHANGE ' . $oldColumn->getQuotedName($this) . ' '
653+
. $this->getColumnDeclarationSQL($newColumn->getQuotedName($this), $newColumnProperties);
654654
}
655655

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

661-
$oldColumnName = new Identifier($oldColumnName);
662-
$columnArray = $column->toArray();
663-
$columnArray['comment'] = $this->getColumnComment($column);
664-
$queryParts[] = 'CHANGE ' . $oldColumnName->getQuotedName($this) . ' '
665-
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray);
661+
$oldColumnName = new Identifier($oldColumnName);
662+
663+
$columnProperties = array_merge($column->toArray(), [
664+
'comment' => $this->getColumnComment($column),
665+
]);
666+
667+
$queryParts[] = 'CHANGE ' . $oldColumnName->getQuotedName($this) . ' '
668+
. $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnProperties);
666669
}
667670

668671
if (isset($diff->addedIndexes['primary'])) {

src/Platforms/DB2Platform.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ public function getAlterTableSQL(TableDiff $diff)
607607
if ($columnDiff->hasCommentChanged()) {
608608
$commentsSQL[] = $this->getCommentOnColumnSQL(
609609
$diff->getName($this)->getQuotedName($this),
610-
$columnDiff->column->getQuotedName($this),
611-
$this->getColumnComment($columnDiff->column),
610+
$columnDiff->getNewColumn()->getQuotedName($this),
611+
$this->getColumnComment($columnDiff->getNewColumn()),
612612
);
613613
}
614614

@@ -702,12 +702,12 @@ private function gatherAlterColumnSQL(
702702
*/
703703
private function getAlterColumnClausesSQL(ColumnDiff $columnDiff): array
704704
{
705-
$column = $columnDiff->column->toArray();
705+
$newColumn = $columnDiff->getNewColumn()->toArray();
706706

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

709-
if ($column['columnDefinition'] !== null) {
710-
return [$alterClause . ' ' . $column['columnDefinition']];
709+
if ($newColumn['columnDefinition'] !== null) {
710+
return [$alterClause . ' ' . $newColumn['columnDefinition']];
711711
}
712712

713713
$clauses = [];
@@ -719,16 +719,16 @@ private function getAlterColumnClausesSQL(ColumnDiff $columnDiff): array
719719
$columnDiff->hasScaleChanged() ||
720720
$columnDiff->hasFixedChanged()
721721
) {
722-
$clauses[] = $alterClause . ' SET DATA TYPE ' . $column['type']->getSQLDeclaration($column, $this);
722+
$clauses[] = $alterClause . ' SET DATA TYPE ' . $newColumn['type']->getSQLDeclaration($newColumn, $this);
723723
}
724724

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

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

733733
if ($defaultClause !== '') {
734734
$clauses[] = $alterClause . ' SET' . $defaultClause;

src/Platforms/OraclePlatform.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -900,13 +900,13 @@ public function getAlterTableSQL(TableDiff $diff)
900900
continue;
901901
}
902902

903-
$column = $columnDiff->column;
903+
$newColumn = $columnDiff->getNewColumn();
904904

905905
// Do not generate column alteration clause if type is binary and only fixed property has changed.
906906
// Oracle only supports binary type columns with variable length.
907907
// Avoids unnecessary table alteration statements.
908908
if (
909-
$column->getType() instanceof BinaryType &&
909+
$newColumn->getType() instanceof BinaryType &&
910910
$columnDiff->hasFixedChanged() &&
911911
count($columnDiff->changedProperties) === 1
912912
) {
@@ -919,13 +919,13 @@ public function getAlterTableSQL(TableDiff $diff)
919919
* Do not add query part if only comment has changed
920920
*/
921921
if (! ($columnHasChangedComment && count($columnDiff->changedProperties) === 1)) {
922-
$columnInfo = $column->toArray();
922+
$newColumnProperties = $newColumn->toArray();
923923

924924
if (! $columnDiff->hasNotNullChanged()) {
925-
unset($columnInfo['notnull']);
925+
unset($newColumnProperties['notnull']);
926926
}
927927

928-
$fields[] = $column->getQuotedName($this) . $this->getColumnDeclarationSQL('', $columnInfo);
928+
$fields[] = $newColumn->getQuotedName($this) . $this->getColumnDeclarationSQL('', $newColumnProperties);
929929
}
930930

931931
if (! $columnHasChangedComment) {
@@ -934,8 +934,8 @@ public function getAlterTableSQL(TableDiff $diff)
934934

935935
$commentsSQL[] = $this->getCommentOnColumnSQL(
936936
$diff->getName($this)->getQuotedName($this),
937-
$column->getQuotedName($this),
938-
$this->getColumnComment($column),
937+
$newColumn->getQuotedName($this),
938+
$this->getColumnComment($newColumn),
939939
);
940940
}
941941

@@ -944,24 +944,24 @@ public function getAlterTableSQL(TableDiff $diff)
944944
. ' MODIFY (' . implode(', ', $fields) . ')';
945945
}
946946

947-
foreach ($diff->renamedColumns as $oldColumnName => $column) {
948-
if ($this->onSchemaAlterTableRenameColumn($oldColumnName, $column, $diff, $columnSql)) {
947+
foreach ($diff->renamedColumns as $oldColumnName => $newColumn) {
948+
if ($this->onSchemaAlterTableRenameColumn($oldColumnName, $newColumn, $diff, $columnSql)) {
949949
continue;
950950
}
951951

952952
$oldColumnName = new Identifier($oldColumnName);
953953

954954
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) .
955-
' RENAME COLUMN ' . $oldColumnName->getQuotedName($this) . ' TO ' . $column->getQuotedName($this);
955+
' RENAME COLUMN ' . $oldColumnName->getQuotedName($this) . ' TO ' . $newColumn->getQuotedName($this);
956956
}
957957

958958
$fields = [];
959-
foreach ($diff->removedColumns as $column) {
960-
if ($this->onSchemaAlterTableRemoveColumn($column, $diff, $columnSql)) {
959+
foreach ($diff->removedColumns as $newColumn) {
960+
if ($this->onSchemaAlterTableRemoveColumn($newColumn, $diff, $columnSql)) {
961961
continue;
962962
}
963963

964-
$fields[] = $column->getQuotedName($this);
964+
$fields[] = $newColumn->getQuotedName($this);
965965
}
966966

967967
if (count($fields) > 0) {

src/Platforms/PostgreSQLPlatform.php

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -522,33 +522,33 @@ public function getAlterTableSQL(TableDiff $diff)
522522
$commentsSQL = [];
523523
$columnSql = [];
524524

525-
foreach ($diff->addedColumns as $column) {
526-
if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) {
525+
foreach ($diff->addedColumns as $newColumn) {
526+
if ($this->onSchemaAlterTableAddColumn($newColumn, $diff, $columnSql)) {
527527
continue;
528528
}
529529

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

533-
$comment = $this->getColumnComment($column);
533+
$comment = $this->getColumnComment($newColumn);
534534

535535
if ($comment === null || $comment === '') {
536536
continue;
537537
}
538538

539539
$commentsSQL[] = $this->getCommentOnColumnSQL(
540540
$diff->getName($this)->getQuotedName($this),
541-
$column->getQuotedName($this),
541+
$newColumn->getQuotedName($this),
542542
$comment,
543543
);
544544
}
545545

546-
foreach ($diff->removedColumns as $column) {
547-
if ($this->onSchemaAlterTableRemoveColumn($column, $diff, $columnSql)) {
546+
foreach ($diff->removedColumns as $newColumn) {
547+
if ($this->onSchemaAlterTableRemoveColumn($newColumn, $diff, $columnSql)) {
548548
continue;
549549
}
550550

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

@@ -561,26 +561,21 @@ public function getAlterTableSQL(TableDiff $diff)
561561
continue;
562562
}
563563

564-
if ($columnDiff->fromColumn !== null) {
565-
$fromColumn = $columnDiff->fromColumn;
566-
} else {
567-
$fromColumn = $columnDiff->getOldColumnName();
568-
}
569-
570-
$oldColumnName = $fromColumn->getQuotedName($this);
564+
$oldColumn = $columnDiff->getOldColumn() ?? $columnDiff->getOldColumnName();
565+
$newColumn = $columnDiff->getNewColumn();
571566

572-
$column = $columnDiff->column;
567+
$oldColumnName = $oldColumn->getQuotedName($this);
573568

574569
if (
575570
$columnDiff->hasTypeChanged()
576571
|| $columnDiff->hasPrecisionChanged()
577572
|| $columnDiff->hasScaleChanged()
578573
|| $columnDiff->hasFixedChanged()
579574
) {
580-
$type = $column->getType();
575+
$type = $newColumn->getType();
581576

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

586581
// here was a server version check before, but DBAL API does not support this anymore.
@@ -589,45 +584,46 @@ public function getAlterTableSQL(TableDiff $diff)
589584
}
590585

591586
if ($columnDiff->hasDefaultChanged()) {
592-
$defaultClause = $column->getDefault() === null
587+
$defaultClause = $newColumn->getDefault() === null
593588
? ' DROP DEFAULT'
594-
: ' SET' . $this->getDefaultValueDeclarationSQL($column->toArray());
595-
$query = 'ALTER ' . $oldColumnName . $defaultClause;
596-
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query;
589+
: ' SET' . $this->getDefaultValueDeclarationSQL($newColumn->toArray());
590+
591+
$query = 'ALTER ' . $oldColumnName . $defaultClause;
592+
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query;
597593
}
598594

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

604600
if ($columnDiff->hasAutoIncrementChanged()) {
605-
if ($column->getAutoincrement()) {
601+
if ($newColumn->getAutoincrement()) {
606602
// add autoincrement
607603
$seqName = $this->getIdentitySequenceName($diff->name, $oldColumnName);
608604

609605
$sql[] = 'CREATE SEQUENCE ' . $seqName;
610606
$sql[] = "SELECT setval('" . $seqName . "', (SELECT MAX(" . $oldColumnName . ') FROM '
611607
. $diff->getName($this)->getQuotedName($this) . '))';
612608
$query = 'ALTER ' . $oldColumnName . " SET DEFAULT nextval('" . $seqName . "')";
613-
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query;
614609
} else {
615610
// Drop autoincrement, but do NOT drop the sequence. It might be re-used by other tables or have
616611
$query = 'ALTER ' . $oldColumnName . ' DROP DEFAULT';
617-
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query;
618612
}
613+
614+
$sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query;
619615
}
620616

621-
$newComment = $this->getColumnComment($column);
622617
$oldComment = $this->getOldColumnComment($columnDiff);
618+
$newComment = $this->getColumnComment($newColumn);
623619

624620
if (
625621
$columnDiff->hasCommentChanged()
626-
|| ($columnDiff->fromColumn !== null && $oldComment !== $newComment)
622+
|| ($columnDiff->getOldColumn() !== null && $oldComment !== $newComment)
627623
) {
628624
$commentsSQL[] = $this->getCommentOnColumnSQL(
629625
$diff->getName($this)->getQuotedName($this),
630-
$column->getQuotedName($this),
626+
$newColumn->getQuotedName($this),
631627
$newComment,
632628
);
633629
}
@@ -637,7 +633,7 @@ public function getAlterTableSQL(TableDiff $diff)
637633
}
638634

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

@@ -688,18 +684,18 @@ public function getAlterTableSQL(TableDiff $diff)
688684
*/
689685
private function isUnchangedBinaryColumn(ColumnDiff $columnDiff): bool
690686
{
691-
$columnType = $columnDiff->column->getType();
687+
$newColumnType = $columnDiff->getNewColumn()->getType();
692688

693-
if (! $columnType instanceof BinaryType && ! $columnType instanceof BlobType) {
689+
if (! $newColumnType instanceof BinaryType && ! $newColumnType instanceof BlobType) {
694690
return false;
695691
}
696692

697-
$fromColumn = $columnDiff->fromColumn instanceof Column ? $columnDiff->fromColumn : null;
693+
$oldColumn = $columnDiff->getOldColumn() instanceof Column ? $columnDiff->getOldColumn() : null;
698694

699-
if ($fromColumn !== null) {
700-
$fromColumnType = $fromColumn->getType();
695+
if ($oldColumn !== null) {
696+
$oldColumnType = $oldColumn->getType();
701697

702-
if (! $fromColumnType instanceof BinaryType && ! $fromColumnType instanceof BlobType) {
698+
if (! $oldColumnType instanceof BinaryType && ! $oldColumnType instanceof BlobType) {
703699
return false;
704700
}
705701

@@ -1326,7 +1322,13 @@ public function getJsonTypeDeclarationSQL(array $column)
13261322

13271323
private function getOldColumnComment(ColumnDiff $columnDiff): ?string
13281324
{
1329-
return $columnDiff->fromColumn !== null ? $this->getColumnComment($columnDiff->fromColumn) : null;
1325+
$oldColumn = $columnDiff->getOldColumn();
1326+
1327+
if ($oldColumn !== null) {
1328+
return $this->getColumnComment($oldColumn);
1329+
}
1330+
1331+
return null;
13301332
}
13311333

13321334
/** @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon. */

0 commit comments

Comments
 (0)