-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[9.x] Add support for native rename/drop column commands #45258
Conversation
@hafezdivandari I like this PR but I wouldn't make it as complicated as to introduce |
Thank you @driesvints, You are right, I agree that it's complicated now, but I think just checking if DBAL is installed or not is not enough, we would need some kind of config for that. do you have any suggestion? For example we currently force user to install |
Are you saying the behavior between using DBAL and native commands is different? If so then I think we might better hold off with this entire PR since it would be too much of a breaking change for many users. I don't think that the |
@driesvints it would be different behavior (breaking change) if I apply your suggestion into this PR:
What am I saying that is we need a switch/config instead of |
I guess I don't understand why that's a problem. If there's a difference in behavior then surely we can't continue with this PR? I expect nothing to change explicitly if someone installs the DBAL package other than it uses DBAL instead of native column rewrites. |
@driesvints This PR, as is, is not a breaking change at all, it only uses native rename/drop if DBAL is not installed and changes nothing else. I was explaining that it would be a breaking change IF I apply your suggestion and remove |
I just merged |
@hafezdivandari but I don't think Dries or I understand WHY it is a breaking change to remove those configuration methods. Just use Doctrine if it is installed and use the native methods if Doctrine is not installed. No configuration methods needed. Why is that a breaking change? Please explain. |
@taylorotwell I think I was wrong using the term "braking change" here, we might see that as an "unexpected behavior". Assume this scenario after this PR, for example on MySQL 8.0:
I added that config method on schema for user to be able to control these situations regardless of DBAL availability. I'm sorry for the confusion, please let me know if you prefer this PR without any config method. |
But the migrations will already have run? You won't run migrations twice. |
@driesvints I agree but you once said: #44101 (comment)
|
That's a good remark. But the main question here remains why a Doctrine rename would be different from a native rename. You say:
Why would there be two renames? What exception would occur? |
A Doctrine rename could be "different" than a native one since on SQLite I'm pretty sure Doctrine drops the column and re-adds it with a new name after storing the data in a temporary table? The final outcome should be the same but the road taken to get there is different. Is that what you mean @hafezdivandari? |
Doctrine can not handle multiple rename/drop, check this tests please but SQLite has no problem with multiple native rename/drop: framework/tests/Database/DatabaseSchemaBlueprintIntegrationTest.php Lines 465 to 506 in 26c476d
Yes, exactly, and also on MySQL the doctrine renames column using
The final outcome also may be different because the way we currently use DBAL is buggy: #45254 Finally is it that bad to use a single config method to control such behavior changes? We are using many config methods on Eloquent Model for example. |
Renamed to |
Sorry, could u please elaborate further, what means 10.0- version for Rename column support for postgres? Does that mean what i can rename natively without doctrine only while using postgres version 10.0 and below? Kinda confused here |
@EdgarSedov sorry for confusion, I wanted to declare that the PostgeSQL and SQL server support native renaming even before that version. It was just a simple comparison to current supported DB version on Laravel. It's corrected now. As stated on the updated Laravel docs on renaming columns you won't need to install DBAL to rename a column on PostgreSQL at all. |
Will this change also fix those long-standing issues with renaming columns when an enum column is present in the table? #1186 |
@IP-Developer Yes, this change fixes that issue. Note: As pointed above, don't forget to call |
@hafezdivandari in this case I guess the same code can be reused in some other places were the enum issue still persists (like db:show command etc.) |
@IP-Developer True. I'm working on it, waiting for this to be reviewed #45598 as a prerequisite. |
@hafezdivandari those are good news for the Laravel community :) Thanks for your work |
Related to #45254
Currently it is required to install
doctrine/dbal
to be able to rename a column on all databases and drop a column on SQLite.But all databases now have native support for renaming and dropping columns on their latest versions:
This PR adds support for native rename column command on all databases and drop column command on SQLite without any breaking changes.
This means if a user has already installed
doctrine/dbal
, they see no change, but for those users with a database version that supports native rename/drop column commands (as listed on the above table) there is no need to installdoctrine/dbal
anymore.But what if I have already installed
doctrine/dbal
and still want to use the native rename/drop column commands?This PR adds a new static method to
Schema
facade,Schema::useNativeSchemaOperationsIfPossible()
. For example if you have already installeddoctrine/dbal
library but you don't want to use Doctrine for renaming/dropping columns you may callSchema::useNativeSchemaOperationsIfPossible()
method within theboot
method of yourApp\Providers\AppServiceProvider
class (we already have similar methods like this one) or maybe inside your migration files directly.Finally, this PR causes Laravel to support native rename/drop column commands and sees the usage of
doctrine\dbal
as a workaround for users that prefer Doctrine or have an old DB version.PS1: I'll send a PR to add/edit Laravel docs if it merged (laravel/docs#8396).
PS2: I'll send a PR with the same approach for changing/modifying columns if this one merged (#45487).