-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Remove Doctrine\DBAL\Types\Type::getDefaultLength() #3255
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
Remove Doctrine\DBAL\Types\Type::getDefaultLength() #3255
Conversation
0aad067 to
1306c3d
Compare
morozov
left a comment
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.
Makes sense.
| */ | ||
| public function getDefaultLength(AbstractPlatform $platform) | ||
| { | ||
| return $platform->getVarcharDefaultLength(); |
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.
Speaking of which, why do we need to know the default type length on the platform level at all? E.g.:
dbal/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Lines 298 to 300 in caf55ee
| if ( !isset($field['length'])) { | |
| $field['length'] = $this->getVarcharDefaultLength(); | |
| } |
We're taking our hard-coded value and passing it explicitly to the field declaraion. Would it make sense to leave the length unspecified if the developer doesn't care? Otherwise, it leads to the pointless expctations like e2e0de2#diff-21fd51266275832f478e50a5b1f22748L219.
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.
Completely unspecified length is probably better: should be explicitly specified by developers anyway.
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.
How portalbe is that? From what I remember MySQL requires maximum length when declaring VARCHAR columns while PostgreSQL doesn't.
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.
There are two points here:
- If a platform doesn't require max length (PostgreSQL), DBAL shouldn't require max length either but it shouldn't provide any hard-coded length in DDL. It should omit it.
- If a platform does require MySQL, DBAL should require it in the column definition but it shouldn't provide any hard-coded length in DDL. It should fail.
This way, if you use only one platform (PostgreSQL) and don't care about portability, you can omit the length and use DBAL w/o any artificial restrictions. Otherwise, you have to explicitly specify the length. It's not the DBAL's job to specify it for you.
Summary
Not used by DBAL itself, only overridden by StringType. Some other types (DateIntervalType) hardcode limits in
getSQLDeclaration()directly.1st step towards #2841 (Refactoring type system).