-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Remove property-based schema comparison APIs #5649
Conversation
$tableDiff->changedColumns['bar'] = new ColumnDiff( | ||
new Column( | ||
'baz', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of the test is invalid.
First of all, the column in $changedColumns
cannot have its name changed. The old and the new column should have the same name to be added to $changedColumns
:
dbal/src/Schema/Comparator.php
Lines 205 to 225 in 58d4b3c
foreach ($fromTableColumns as $column) { | |
$columnName = strtolower($column->getName()); | |
// See if column is removed in "to" table. | |
if (! $toTable->hasColumn($columnName)) { | |
$tableDifferences->removedColumns[$columnName] = $column; | |
$changes++; | |
continue; | |
} | |
$toColumn = $toTable->getColumn($columnName); | |
if ($this->columnsEqual($column, $toColumn)) { | |
continue; | |
} | |
$tableDifferences->changedColumns[$column->getName()] = new ColumnDiff( | |
$toColumn, | |
$this->diffColumn($column, $toColumn), | |
$column, | |
); |
Second, the test expects a rename column SQL to be generated for MySQL:
. "CHANGE bar baz VARCHAR(255) DEFAULT 'def' NOT NULL, " |
But not on Oracle:
"ALTER TABLE mytable MODIFY (baz VARCHAR2(255) DEFAULT 'def' NOT NULL, " |
Note that the latter assumes that the column name is already "baz", not "bar".
1697596
to
343526d
Compare
return [ | ||
'ALTER TABLE mytable ADD quota INT', | ||
'ALTER TABLE mytable DROP COLUMN foo', | ||
'ALTER TABLE mytable ALTER COLUMN baz NVARCHAR(255) NOT NULL', | ||
"ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_78240498 DEFAULT 'def' FOR baz", | ||
'ALTER TABLE mytable ALTER COLUMN bloo BIT NOT NULL', | ||
'ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_CECED971 DEFAULT 0 FOR bloo', | ||
"sp_rename 'mytable', 'userlist'", | ||
"DECLARE @sql NVARCHAR(MAX) = N''; " . | ||
"SELECT @sql += N'EXEC sp_rename N''' + dc.name + ''', N''' " . | ||
"+ REPLACE(dc.name, '6B2BD609', 'E2B58069') + ''', ''json'';' " . | ||
'FROM sys.default_constraints dc ' . | ||
'JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id ' . | ||
"WHERE tbl.name = 'userlist';" . | ||
'EXEC sp_executesql @sql', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assertions where the expected SQL was copy-pasted from the debugger don't add any value. The only thing they prove is that the generated SQL will not accidentally change which complicates changing code (including fixing bugs and refactoring). As the above comment shows, the expected SQL is not always correct.
public function testDiffDecimalWithNullPrecision(): void | ||
{ | ||
$column = new Column('foo', Type::getType('decimal')); | ||
$column->setPrecision(null); | ||
|
||
$column2 = new Column('foo', Type::getType('decimal')); | ||
|
||
self::assertEquals([], $this->comparator->diffColumn($column, $column2)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test only tests that the default precision is null. It is pointless.
public function testCompareGuidColumns(): void | ||
{ | ||
$column1 = new Column('foo', Type::getType('guid'), ['comment' => 'GUID 1']); | ||
$column2 = new Column( | ||
'foo', | ||
Type::getType('guid'), | ||
['notnull' => false, 'length' => 36, 'fixed' => true, 'default' => 'NEWID()', 'comment' => 'GUID 2.'], | ||
); | ||
|
||
self::assertEquals(['notnull', 'default', 'comment'], $this->comparator->diffColumn($column1, $column2)); | ||
self::assertEquals(['notnull', 'default', 'comment'], $this->comparator->diffColumn($column2, $column1)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comparator no longer needs to be aware of platform-specific type implementation details. This is taken care of in the platform-aware schema comparison.
@@ -1064,39 +1058,6 @@ public function assertSchemaSequenceChangeCount( | |||
self::assertCount($removeSequenceCount, $diff->removedSequences); | |||
} | |||
|
|||
public function testDiffColumnPlatformOptions(): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes in platform options are no longer exposed via the column diff as they were never used anywhere except for this test.
343526d
to
c08335c
Compare
c08335c
to
b983192
Compare
b983192
to
b9141e9
Compare
src/Schema/ColumnDiff.php
Outdated
|
||
// Null values need to be checked additionally as they tell whether to create or drop a default value. | ||
// null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation. | ||
if (($newDefault === null) !== ($oldDefault === null)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (($newDefault === null) !== ($oldDefault === null)) { | |
if (($newDefault === null) xor ($oldDefault === null)) { |
Maybe it's a me-only problem but !==
on booleans makes my head spin. 😓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious what it would look like if we wanted to check them for equality 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's start an RFC to add the xnor
operator to PHP. 😁
b9141e9
to
e7b326c
Compare
TODO: