-
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
[5.6] Temporal columns improvements (broken by GitHub) #22000
[5.6] Temporal columns improvements (broken by GitHub) #22000
Conversation
edc9a1a
to
8e93342
Compare
I'll be the annoying guy that talks about breaking changes. I've got years worth of migrations, and if any of these migrations are generating another database structure than at the time they were initially run, then it's a breaking change. I have much higher requirements on the stability of migrations than I have on other parts of the code; the migrations works with the production database that lives for years even when the code base can be rewritten at will. A quick check for breaking changes; reset your database (rollback+migrate) and see if your local development environment exactly matches the production database that has executed the migrations one-at-a-time over a long period of time. Think years or several major Laravel releases when thinking "long period of time". Your changes to SqlServerGrammar::typeDateTime and typeTimestamp will drop our SQL Server 2005 support since it does not support datetime2. How about introducing a |
@sisve If I'm not wrong, as I commented on laravel/ideas#870, researching MSDN, Wikipedia and this top Google ranked source I've found that all these column types come from SQL Server 10.0 (2008): If intended I can rebase this to 5.6 or to revert some unwanted change. It should be noted on the second commit that some implementations was using column precision even when not being used (I've not tested but I guess this would break code), some was respecting column precision when using |
Closing here temporarily to rebase the branch to revert the |
We're now trapped in two parallel discussions, this PR and the linked internals issue. Anyhow, I would help determining the scope of this PR if we could list all resulting database changes. I'm more worried about changes into the generated database than what method is now aliasing something else. We've already found one, $table->datetime('test') is changed from I would prefer if this list of changes was empty; that would cause the least amount of issues when upgrading. It's my personal view that the list must be empty if you're targetting 5.5, we can not change how people's migrations work in the middle of a release. Imagine the support nightmare; "Hey, my coworker got a datetime2 column but I only got a datetime column. We're both on Laravel 5.5"... It's my personal view that the list must be empty if you're targetting 5.6 too. This is where I believe I am a bit controversial; but I would not like to see any breaking change to any migration code. Migrations live a long time, and needs to be stable for an equally long time. No matter what; the list of changes needs to be documented so they can go into changelogs/upgrade documentation if someone less strict that me merges it. |
Ouch, I've rebased a lot of times when the PR was opened, once I closed and rebased I cannot reopen again - what a shame, GitHub. 😒 I'll open a new PR now targeting 5.6 and with the |
I was unsure if I have to push this to 5.5 or 5.6, but since it affects only new created columns and fixes/improves a lot of expected behavior I guess it would be wanted for 5.5.If intended I can rebase this to 5.6 or to revert some unwanted change. 👍
Once again my contribution ended up big and I had to split it with 4 commits to ease the review - it's a lot easier to see the changes separately. I also prepared an extensive summary of changes to help reviewing. 😃
Part 1: Ensure unsupported temporal columns reuse supported ones
Basic code cleanup and consistency improvement. No tests changes yet.
Changes:
Illuminate\Database\Schema\Grammars\MySqlGrammar
typeTimeTz()
totypeTime()
Illuminate\Database\Schema\Grammars\PostgresGrammar
typeDateTime()
totypeTimestamp()
typeDateTimeTz()
totypeTimestampTz()
Illuminate\Database\Schema\Grammars\SQLiteGrammar
typeTimestamp()
implementation totypeDateTime()
and aliastypeTimestamp()
totypeDateTime()
typeDateTimeTz()
totypeDateTime()
typeTimeTz()
totypeTime()
typeTimestampTz()
totypeDateTimeTz()
Illuminate\Database\Schema\Grammars\SqlServerGrammar
typeTimestamp()
implementation totypeDateTime()
and aliastypeTimestamp()
totypeDateTime()
typeTimestampTz()
implementation totypeDateTimeTz()
and aliastypeTimestampTz()
totypeDateTimeTz()
typeTimeTz()
totypeTime()
Benefits:
useCurrent()
ondateTime()
anddateTimeTz()
columns (this is improved later)Part 2: Ensure temporal columns handle precision correctly
Improves temporal columns precision handling with full SQL standard compliance. Adds 8 new tests and 76 assertions.
Changes to code:
Illuminate\Database\Schema\Blueprint
$precision
argument to the missingtimeTz()
methodIlluminate\Database\Schema\Grammars\MySqlGrammar
Illuminate\Database\Schema\Grammars\PostgresGrammar
Illuminate\Database\Schema\Grammars\SqlServerGrammar
typeTime()
andtypeTimeTz()
to correctly handle the given column precisionChanges to tests:
Illuminate\Tests\Database\DatabaseMySqlSchemaGrammarTest
Illuminate\Tests\Database\DatabasePostgresSchemaGrammarTest
Illuminate\Tests\Database\DatabaseSQLiteSchemaGrammarTest
Illuminate\Tests\Database\DatabaseSqlServerSchemaGrammarTest
testSoftDeletes()
andtestSoftDeletesTz()
testsBenefits:
TIME
,DATETIME
andTIMESTAMP
columnsPart 3: Ensure all temporal columns handle useCurrent() as supported
Improves all temporal columns to handle the
useCurrent()
column modifier as supported by the database driver in use. Adds 28 new tests and 56 assertions, drops 3 existing tests and 12 assertions.Changes to code:
Illuminate\Database\Schema\Grammars\Grammar
setTemporalDefaut()
protected methodIlluminate\Database\Schema\Grammars\MySqlGrammar
Illuminate\Database\Schema\Grammars\PostgresGrammar
Illuminate\Database\Schema\Grammars\SQLiteGrammar
Illuminate\Database\Schema\Grammars\SqlServerGrammar
setTemporalDefault()
methoduseCurrent
handling*Why I have changed this to use a new method? Because it simplifies things and also ensures the SQL grammars always generate
DEFAULT
expressions afterNULL
/NOT NULL
expressions. All current drivers supportDEFAULT
expressions in either position but theirCREATE TABLE
documentation syntax always placeDEFAULT
expressions afterNOT
/NOT NULL
expressions - thus we can say it's less risky to break if for any reason they change this behavior.Changes to tests:
Illuminate\Tests\Database\DatabaseSchemaBlueprintTest
testDefaultCurrentTimestamp()
method in favor of new grammar-specific testsIlluminate\Tests\Database\DatabaseMySqlSchemaGrammarTest
testAddingTimestampWithDefault()
andtestAddingTimestampTzWithDefault()
methods in favor of new grammar-specific testsIlluminate\Tests\Database\DatabaseMySqlSchemaGrammarTest
Illuminate\Tests\Database\DatabasePostgresSchemaGrammarTest
Illuminate\Tests\Database\DatabaseSQLiteSchemaGrammarTest
Illuminate\Tests\Database\DatabaseSqlServerSchemaGrammarTest
useCurrent()
to all temporal columnsBenefits:
useCurrent()
column modifier on supported temporal columnsPart 4: Improve temporal columns docblocks
Misc docblocks improvements to temporal columns. We're done. 😅
Benefits:
If I didn't miss anything, it's all good. Tests are passing. 👍