[9.x] Enhance column modifying#43541
[9.x] Enhance column modifying#43541hafezdivandari wants to merge 7 commits intolaravel:9.xfrom hafezdivandari:9.x
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. |
| } | ||
|
|
||
| if ($fluent['type'] === 'binary') { | ||
| $options['length'] = AbstractMySQLPlatform::LENGTH_LIMIT_BLOB; |
There was a problem hiding this comment.
Why use MySQL platform? What if user is using SQL Server?
There was a problem hiding this comment.
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.
Laravel timestamp type maps to Doctrine datetime type:
- MySQL supports
timestampif$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
versionoption here: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/AbstractPlatform.php#L4451
- PostreSQL supports
timestampandtimestampTz:- Mapping: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/PostgreSQLPlatform.php#L1179-L1180
- Declaration: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/PostgreSQLPlatform.php#L1025-L1036
- SQLite platform maps
timestamptodatetime:- Mapping: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/SqlitePlatform.php#L778
- Declaration: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/SqlitePlatform.php#L319-L322
- SQLServer has no mapping for
timestamp(doesn't support)
There was a problem hiding this comment.
What does "version" = true even mean though?
|
|
||
| if ($fluent['type'] === 'jsonb') { | ||
| $options['platformOptions'] = [ | ||
| 'jsonb' => true, |
There was a problem hiding this comment.
What does this do? Why is it needed?
There was a problem hiding this comment.
Only PostgreSQL supports jsonb:
- Maps
jsonbtojson: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/PostgreSQLPlatform.php#L1169 - Uses
jsonboption: https://github.com/doctrine/dbal/blob/36b9ffc15c31598baa2a37b1abdd5b860d5c164f/src/Platforms/PostgreSQLPlatform.php#L1315-L1322
| 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.
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
binarycolumn that were being changed toLONGBLOBinstead ofBLOB.Here is the Doctrine type mapping of: