-
-
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
Deprecate renaming tables via TableDiff #5663
Conversation
src/Platforms/SQLServerPlatform.php
Outdated
"DECLARE @sql NVARCHAR(MAX) = N''; " | ||
. "SELECT @sql += N'EXEC sp_rename N''' + dc.name + ''', N''' " | ||
. "+ REPLACE(dc.name, '" . $this->generateIdentifierName($oldName) | ||
. "', " | ||
. "'" . $this->generateIdentifierName($newName) . "') + ''', ''OBJECT'';' " | ||
. 'FROM sys.default_constraints dc ' | ||
. 'JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id ' | ||
. 'WHERE tbl.name = ' . $this->quoteStringLiteral($newName) . ';' | ||
. '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.
I think it's fine to have linebreaks inside this string and that this looks a job for nowdoc + sprintf.
"DECLARE @sql NVARCHAR(MAX) = N''; " | |
. "SELECT @sql += N'EXEC sp_rename N''' + dc.name + ''', N''' " | |
. "+ REPLACE(dc.name, '" . $this->generateIdentifierName($oldName) | |
. "', " | |
. "'" . $this->generateIdentifierName($newName) . "') + ''', ''OBJECT'';' " | |
. 'FROM sys.default_constraints dc ' | |
. 'JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id ' | |
. 'WHERE tbl.name = ' . $this->quoteStringLiteral($newName) . ';' | |
. 'EXEC sp_executesql @sql', | |
sprintf( | |
<<<'SQL' | |
DECLARE @sql NVARCHAR(MAX) = N''; | |
SELECT @sql += N'EXEC sp_rename N''' + dc.name + ''', N''' | |
+ REPLACE(dc.name, '%s', '%s') + ''', ''OBJECT'';' | |
FROM sys.default_constraints dc | |
JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id | |
WHERE tbl.name = %s; | |
EXEC sp_executesql @sql' | |
SQL, | |
$this->generateIdentifierName($oldName), | |
$this->generateIdentifierName($newName), | |
$this->quoteStringLiteral($newName) | |
) |
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.
It was a copy-paste from getAlterTableSQL()
which actually didn't need to be duplicated. I removed the original code and made the logic of the new method reused.
634a403
to
217ce8d
Compare
Schema comparators do not detect renamed tables, so they do not populate
TableDiff::$newName
. Schema managers doing so in theirrenameTable()
methods is a hack.For comparison,
ColumnDiff
does not represent a change in the column name, it is tracked at a higher level, inTableDiff
. By the same token,TableDiff
should not represent a change in the table name. If it will be ever supported, it should be tracked inSchemaDiff
.Getting rid of handling the new name in the table diff is a prerequisite for future refactoring of the
TableDiff
API. Eventually, I want to get rid of public properties there and make the object immutable similar to what was done inColumnDiff
(#5657).