-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[9.x] Enhance column modifying #43541
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
There are several breaking changes to method signatures in this PR. |
@driesvints I fixed that in a new commit and reverted all changes on method signatures. |
$options['length'] = static::calculateDoctrineTextLength($fluent['type']); | ||
} | ||
|
||
if ($fluent['type'] === 'binary') { | ||
$options['length'] = AbstractMySQLPlatform::LENGTH_LIMIT_BLOB; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use MySQL platform? What if user is using SQL Server?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Laravel binary
type maps to Doctrine blob
type and only MySQL uses length
option:
- MySQL: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/AbstractMySQLPlatform.php#L1270-L1289
- SQLServer: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/SQLServerPlatform.php#L1614-L1617
- PostreSQL: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/PostgreSQLPlatform.php#L1273-L1276
- SQLite: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/SqlitePlatform.php#L857-L860
if (static::doesntNeedCharacterOptions($fluent['type'])) { | ||
if ($fluent['type'] === 'timestamp') { | ||
$options['platformOptions'] = [ | ||
'version' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Laravel timestamp
type maps to Doctrine datetime
type:
- MySQL supports
timestamp
if$options['platformOptions']['version']
is set:- Mapping: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/AbstractMySQLPlatform.php#L1176
- Declaration: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/AbstractMySQLPlatform.php#L290-L297
- Declares the
version
option here: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/AbstractPlatform.php#L4451
- PostreSQL supports
timestamp
andtimestampTz
: - SQLite platform maps
timestamp
todatetime
: - SQLServer has no mapping for
timestamp
(doesn't support)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "version" = true
even mean though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
if ($fluent['type'] === 'jsonb') { | ||
$options['platformOptions'] = [ | ||
'jsonb' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do? Why is it needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only PostgreSQL supports jsonb
:
default => 255 + 1, | ||
'tinyText' => AbstractMySQLPlatform::LENGTH_LIMIT_TINYTEXT, | ||
'text' => AbstractMySQLPlatform::LENGTH_LIMIT_TEXT, | ||
'mediumText' => AbstractMySQLPlatform::LENGTH_LIMIT_MEDIUMTEXT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why MySQL specific?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only MySQL uses length
option on text
type:
- MySQL: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/AbstractMySQLPlatform.php#L266-L285
- PostgreSQL: https://github.com/doctrine/dbal/blob/3.4.x/src/Platforms/PostgreSQLPlatform.php#L1082-L1085
- SQLServer: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/SQLServerPlatform.php#L1313-L1316
- SQLite: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/SqlitePlatform.php#L514-L517
Please mark as ready for review when all questions are answered. Thanks. |
@taylorotwell Thank you for reviewing this PR. I answered all. |
Thanks for your pull request to Laravel! Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include. If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions! If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response. |
Before this PR, we were manually map Laravel column types to its Doctrine equivalent and many types were missing, this PR uses each database platform own map instead. So we can support modifying many more columns, e.g.
double
,float
,jsonb
,set
,timeTz
,timestamp
(no need to register a custom Doctrine type class),timestampTz
,tinyText
,unsignedDecimal
,unsignedDouble
,unsignedFloat
,year
, etc.It also fix a bug when modifying a
binary
column that were being changed toLONGBLOB
instead ofBLOB
.Here is the Doctrine type mapping of: