-
Notifications
You must be signed in to change notification settings - Fork 11.8k
[10.x] Add support for native column modifying #45487
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
Conversation
|
Can you elaborate on point 3 and point 6 in your PR description? This only applies to changing columns? Can you give some examples of what would work and what wouldn't work?
|
@taylorotwell sure. It's not just about modifying columns, currently on creating a table or adding a column, the CREATE TABLE users (
id bigint unsigned not null auto_increment,
name varchar(255) not null,
primary key (id, name)
);but you can't do this on Laravel, because Ok that was the whole picture, but when you want to modify a column with but PostgreSQL and SQL Server doesn't accept that when altering a column. it means you can't control the adding/dropping of a primary key when changing a column. That is what I tried to explain on point 3 and 6. As I said this needs another BC PR to change what PS: Related to this, the SingleStore DB has |
|
OK, but for adding columns everything still works as before on 9.x? However, when modifying columns, can you give an example of some actual migration code that would now throw an error after this PR? |
|
Yes, for adding everything works as before. And when modifying an auto-increment column, no error would be thrown but there are some differences in compare to when adding a column: Examples of
|
|
OK - this is a pretty risky PR I think but I'm willing to take a chance on it since it would be nice to not have doctrine/dbal for changing columns. |
Related to #45258, this PR adds support for native column modifying and drops necessity of installing
doctrine/dbalwhen modifying columns usingchange()on MariaDB, MySQL, PostgreSQL and SQL Server.Supported databases, modifiers and types:
after,first,autoIncrement,from,storedAs,storedAsJson,virtualAs,virtualAsJson,invisible,unsigned,nullable,default,charset,collation,comment,useCurrent,useCurrentOnUpdate,srid,renameTo2autoIncrement3,from,storedAs4,generatedAs,always,nullable,default,collation,comment,useCurrent,isGeometry,projectionenum5autoIncrement6,nullable,default,collation,persisted,useCurrentenum7Notes:
col1is defined as:renameColumncommand afterchangecommand:renameTocolumn modifier on MySQL to rename and modify a column at one go:autoIncrementon PostgreSQL asprimary keyand also causes column type to beserial. This PR partially supportsautoIncrement, it means theautoIncrementmodifier still causes a column type to beserialtype and you may usefrommodifier to set it's starting value, but it doesn't add or drop the primary key. You may useprimary()andprimary(false)commands explicitly to achieve this.storedAsmodifier is not supported on this PR. However, it is supported to setstoredAs(null)explicitly on PostgreSQL >= 13.0 to drop the generated column expression (turns a stored generated column into a normal base column).enumbut the syntax is different, Laravel uses a check constraint on avarcharwhen adding anenumtype. This PR doesn't handle modifyingenumtype on PostgreSQL.autoIncrementmodifier asidentity primary keyon SQL Server. SQL Server doesn't support adding / droppingidentityandprimary keywhen using alter column. So this PR also doesn't support that. You may useprimary()andprimary(false)commands explicitly to achieve this.enumand Laravel is using a check constraint on anvarcharwhen adding anenumtype. This PR doesn't support modifyingenumon SQL Server.What if I have already installed
doctrine/dbal?Just like #45258, if you have already installed Doctrine DBAL, you have to call
Schema::useNativeSchemaOperationsIfPossible()method within thebootmethod of yourApp\Providers\AppServiceProviderclass or within your migrations files to be able to use native schema operations.