Repository navigation
Fix changing a column on PostgreSQL and SQL Server - #259
Closed
JonasPardon wants to merge 5 commits into
Closed
JonasPardon wants to merge 5 commits into
JonasPardon wants to merge 5 commits into
Conversation
The ->change() shims used isset() to decide whether the migration set a modifier, which is false for null, so ->default(null) kept the old default instead of removing it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…MariaDB The change shim read the existing column with the modifier names, so the collation was never kept, and passed reported defaults through as strings: MariaDB's NULL became the string 'NULL' and CURRENT_TIMESTAMP was quoted. It also compiled every changed column for each change command. Keep the unset attributes on a copy of the column, normalise the reported default per server, and let Laravel compile the one column of each command. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ->change() shims compiled the kept attributes as a new column definition, which PostgreSQL and SQL Server reject. Copy them onto the changed column instead and let Laravel compile it, as for MySQL and MariaDB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Following up on this question on #258: the
->change()shim generates invalid SQL on PostgreSQL and SQL Server onwip/1.3. SQLite is fine: it keeps every attribute, apart from->default(null), which #254 fixes.I ran the same migrations on PostgreSQL 16.15 against Winter 1.2 (Laravel 9 + DBAL), current
wip/1.3, and this branch, and on SQL Server 2022 againstwip/1.3and this branch:->change()without restating the attributewip/1.3nullable()alter column "a" not null'foo',0.00)alter column "a" default …O'Briendefault')useCurrent()timestamp, made nullableCURRENT_TIMESTAMPCcollationIncorrect syntax near the keyword 'default'Latin1_General_BINcollationCauses:
getColumns()without thechangeflag, so Laravel's PostgreSQL modifiers compile it as a new column (null,default 'foo') instead ofdrop not nullandset default. On SQL Server,modifyDefault()adds an inline default, whichalter columndoesn't accept.'foo'::character varying,('foo'),(getdate())).collatewhilegetColumns()reportscollation.compileChange()compiled every changed column for eachchangecommand.Changes:
compileChange()compile it. Unlike Fix changing a column on MySQL, MariaDB, PostgreSQL and SQL Server #258, the attributes are set on the column itself and not on a copy, because PostgreSQL compiles the comment and SQL Server the default in separate commands that run after the change.Expression.alter column "name" nullnow expectsdrop not null.ColumnDefinition::$nameaccess.What it doesn't change: Laravel's own behavior stays. On PostgreSQL a change also emits
drop identity if existsfor a column that isn't auto-incrementing, andcomment on column … is NULLwhen the column has no comment. On SQL Server a primary key column still can't be changed, sobigIncrements('id')->change()fails on the primary key constraint as it does without the shim. Winter 1.2 dropped the collation on PostgreSQL. This keeps it, as on MySQL.This builds on #258 (and #254), and uses the
existingColumns()test helper from #258, so it includes their commits. Only the last commit is new. The diff gets smaller once those are merged.🤖 Generated with Claude Code