-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Implement an EnumType for MySQL/MariaDB #6536
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
be4bcc4
to
e2688d8
Compare
e2688d8
to
be7d0e6
Compare
I'm just curious, if you've decided to implement partial support for I know you rejected this idea here doctrine/migrations#1441 (comment), but to me, it seems like the simplest and most flexible solution to implement. However, I might be missing something. |
@berkut1 the VerbatimType to be used during schema introspection solves a different need that having an EnumType in DBAL (even though there is indeed some overlap when considering the case of introspecting a database containing an enum field). |
2bb4731
to
2f81998
Compare
What @stof said, basically. I still believe a verbatim type is useful because I don't want to continuously catch up with obscure types that anyone might be using out there. But MySQL enums are pretty popular and I've seen so many workarounds in the wild that I felt like we should do something in the core to accommodate projects that rely on ENUM columns. |
0f5cfd2
to
3c462e4
Compare
cf3001f
to
3811651
Compare
3811651
to
ad34f74
Compare
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
|
||
final class EnumType extends Type |
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 do you make the class final? Other types are not final
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 would you want to extend it?
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.
Well e.g. my custom enum types could extend it, and then it'd be clear hierarchy, that this is an enum related type. Its not critical, but there is just one other type (AsciiStringType
) that is final, so I don't see reason why limit the inheritance specifically for EnumType
, all other types are open.
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.
You don't need that hierarchy. This class contains a single method which is just a delegate to a platform method. Extending this class is absolutely pointless.
And we can discuss finalizing the other types for the sake of consistency as well, if you like. 😉
throw ColumnValuesRequired::new($this, 'ENUM'); | ||
} | ||
|
||
return $this->getStringTypeDeclarationSQL(['length' => max(...array_map(mb_strlen(...), $column['values']))]); |
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.
max
accepts an array.
return $this->getStringTypeDeclarationSQL(['length' => max(...array_map(mb_strlen(...), $column['values']))]); | |
return $this->getStringTypeDeclarationSQL(['length' => max(array_map(mb_strlen(...), $column['values']))]); |
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.
It does, but why's that better than using the ...
operator? 🤔
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.
3 bytes less 😅
That generates some less OPcode operations. https://3v4l.org/GjuE7/vld
* 4.2.x: Implement an EnumType for MySQL/MariaDB (doctrine#6536) Leverage the new PDO subclasses (doctrine#6532) PHPStan 1.12.6 (doctrine#6535)
With `doctrine/dbal 4.2.0` the `enum` has been added directly in DBAL, implementing it slightly different than the original TYPO3 implementation, which has been mitigated with #105279 and adopted for the `set` type in advance with #105294. TYPO3 still needs to adopt the options reading existing database schema provided by a trait to the extended platform classes and missed to pass the `enum` and `set` option values as `values` to the `Column` objects instead as `platformOption` key, hidden by the fact that getting the array representation of a column merges the platformOptions on the same level with the direct value options. Upcoming `doctrine/dbal` introduces more phpdoc-block array shapes, narrowing down possible (allowed) array keys for `platformOptions` and failing with phpstan in core tests while not beeing a technical issue. This change adjusts related code within the `ext_tables.sql` related `TableBuilder` and the platform trait reading the values and setting it to `Column` objects as value property instead of `platformOption`. Considered as task and not as bugfix due to the fact that this is only static code analysis related and not technically breaking. Minor left-over in the `SetType` implementation for `doctrine/dbal 4.0` is removed along the way. Tested and extracted from doctrine/dbal 4.3.x test, see: https://review.typo3.org/c/Packages/TYPO3.CMS/+/88596 [1] doctrine/dbal#6536 [2] https://github.com/doctrine/dbal/releases/tag/4.2.0 Resolves: #106486 Related: #105294 Related: #105279 Releases: main, 13.4 Change-Id: Ib40d8d684fdce840e4050387416227d56e39698b Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/88905 Tested-by: core-ci <[email protected]> Reviewed-by: Georg Ringer <[email protected]> Reviewed-by: Garvin Hicking <[email protected]> Tested-by: Garvin Hicking <[email protected]> Tested-by: Georg Ringer <[email protected]>
With `doctrine/dbal 4.2.0` the `enum` has been added directly in DBAL, implementing it slightly different than the original TYPO3 implementation, which has been mitigated with #105279 and adopted for the `set` type in advance with #105294. TYPO3 still needs to adopt the options reading existing database schema provided by a trait to the extended platform classes and missed to pass the `enum` and `set` option values as `values` to the `Column` objects instead as `platformOption` key, hidden by the fact that getting the array representation of a column merges the platformOptions on the same level with the direct value options. Upcoming `doctrine/dbal` introduces more phpdoc-block array shapes, narrowing down possible (allowed) array keys for `platformOptions` and failing with phpstan in core tests while not beeing a technical issue. This change adjusts related code within the `ext_tables.sql` related `TableBuilder` and the platform trait reading the values and setting it to `Column` objects as value property instead of `platformOption`. Considered as task and not as bugfix due to the fact that this is only static code analysis related and not technically breaking. Minor left-over in the `SetType` implementation for `doctrine/dbal 4.0` is removed along the way. Tested and extracted from doctrine/dbal 4.3.x test, see: https://review.typo3.org/c/Packages/TYPO3.CMS/+/88596 [1] doctrine/dbal#6536 [2] https://github.com/doctrine/dbal/releases/tag/4.2.0 Resolves: #106486 Related: #105294 Related: #105279 Releases: main, 13.4 Change-Id: Ib40d8d684fdce840e4050387416227d56e39698b Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/88905 Tested-by: core-ci <[email protected]> Reviewed-by: Georg Ringer <[email protected]> Reviewed-by: Garvin Hicking <[email protected]> Tested-by: Garvin Hicking <[email protected]> Tested-by: Georg Ringer <[email protected]>
With `doctrine/dbal 4.2.0` the `enum` has been added directly in DBAL, implementing it slightly different than the original TYPO3 implementation, which has been mitigated with #105279 and adopted for the `set` type in advance with #105294. TYPO3 still needs to adopt the options reading existing database schema provided by a trait to the extended platform classes and missed to pass the `enum` and `set` option values as `values` to the `Column` objects instead as `platformOption` key, hidden by the fact that getting the array representation of a column merges the platformOptions on the same level with the direct value options. Upcoming `doctrine/dbal` introduces more phpdoc-block array shapes, narrowing down possible (allowed) array keys for `platformOptions` and failing with phpstan in core tests while not beeing a technical issue. This change adjusts related code within the `ext_tables.sql` related `TableBuilder` and the platform trait reading the values and setting it to `Column` objects as value property instead of `platformOption`. Considered as task and not as bugfix due to the fact that this is only static code analysis related and not technically breaking. Minor left-over in the `SetType` implementation for `doctrine/dbal 4.0` is removed along the way. Tested and extracted from doctrine/dbal 4.3.x test, see: https://review.typo3.org/c/Packages/TYPO3.CMS/+/88596 [1] doctrine/dbal#6536 [2] https://github.com/doctrine/dbal/releases/tag/4.2.0 Resolves: #106486 Related: #105294 Related: #105279 Releases: main, 13.4 Change-Id: Ib40d8d684fdce840e4050387416227d56e39698b Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/88913 Tested-by: core-ci <[email protected]> Reviewed-by: Stefan Bürk <[email protected]> Tested-by: Stefan Bürk <[email protected]>
With `doctrine/dbal 4.2.0` the `enum` has been added directly in DBAL, implementing it slightly different than the original TYPO3 implementation, which has been mitigated with #105279 and adopted for the `set` type in advance with #105294. TYPO3 still needs to adopt the options reading existing database schema provided by a trait to the extended platform classes and missed to pass the `enum` and `set` option values as `values` to the `Column` objects instead as `platformOption` key, hidden by the fact that getting the array representation of a column merges the platformOptions on the same level with the direct value options. Upcoming `doctrine/dbal` introduces more phpdoc-block array shapes, narrowing down possible (allowed) array keys for `platformOptions` and failing with phpstan in core tests while not beeing a technical issue. This change adjusts related code within the `ext_tables.sql` related `TableBuilder` and the platform trait reading the values and setting it to `Column` objects as value property instead of `platformOption`. Considered as task and not as bugfix due to the fact that this is only static code analysis related and not technically breaking. Minor left-over in the `SetType` implementation for `doctrine/dbal 4.0` is removed along the way. Tested and extracted from doctrine/dbal 4.3.x test, see: https://review.typo3.org/c/Packages/TYPO3.CMS/+/88596 [1] doctrine/dbal#6536 [2] https://github.com/doctrine/dbal/releases/tag/4.2.0 Resolves: #106486 Related: #105294 Related: #105279 Releases: main, 13.4 Change-Id: Ib40d8d684fdce840e4050387416227d56e39698b Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/88913 Tested-by: core-ci <[email protected]> Reviewed-by: Stefan Bürk <[email protected]> Tested-by: Stefan Bürk <[email protected]>
Summary
This PR adds an
EnumType
that allows us to introspect and diff tables that make use of MySQL'sENUM
column type.