-
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
[10.x] Add support for native column modifying #45487
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/dbal
when 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
,renameTo
2autoIncrement
3,from
,storedAs
4,generatedAs
,always
,nullable
,default
,collation
,comment
,useCurrent
,isGeometry
,projection
enum
5autoIncrement
6,nullable
,default
,collation
,persisted
,useCurrent
enum
7Notes:
col1
is defined as:renameColumn
command afterchange
command:renameTo
column modifier on MySQL to rename and modify a column at one go:autoIncrement
on PostgreSQL asprimary key
and also causes column type to beserial
. This PR partially supportsautoIncrement
, it means theautoIncrement
modifier still causes a column type to beserial
type and you may usefrom
modifier 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.storedAs
modifier 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).enum
but the syntax is different, Laravel uses a check constraint on avarchar
when adding anenum
type. This PR doesn't handle modifyingenum
type on PostgreSQL.autoIncrement
modifier asidentity primary key
on SQL Server. SQL Server doesn't support adding / droppingidentity
andprimary key
when using alter column. So this PR also doesn't support that. You may useprimary()
andprimary(false)
commands explicitly to achieve this.enum
and Laravel is using a check constraint on anvarchar
when adding anenum
type. This PR doesn't support modifyingenum
on 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 theboot
method of yourApp\Providers\AppServiceProvider
class or within your migrations files to be able to use native schema operations.