-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
v2.72 breaks doctrine date/time precision with mariadb 10.11 #2897
Comments
Hello, I recommend you set your default explicitly: \Carbon\Doctrine\DateTimeDefaultPrecision::set(6); Or set the precision for each field. You can also choose to install Default value can no longer be handled the same way with dbal v4. That's why it's now externalized in a separate package |
Thanks for getting back so quick.
Not sure if this will work as this is only called if the Setting it on each field in my current project would mean to abandon some shared functionality like TimestampableEntity Trait from https://github.com/doctrine-extensions/DoctrineExtensions Downgrading carbon-doctrine-types might work but seems to limit doctrine/dbal to 3.6. For now it makes more sense to stay at 2.71, at least in the current project i'm working on. |
It should because (using latest versions: carbon 2.71, dbal 4, carbon-doctrine-types 3) and setting default precision to 6, I can't see anything that would still gives you 10. At least it would not come from Carbon, nor carbon-doctrine-types (nor from Doctrine default values AFAIK). If In the meantime you can also extend the class: doctrine:
dbal:
types:
datetime_immutable: \YourOwnApp\Doctrine\DateTimeImmutableType
datetime: \YourOwnApp\Doctrine\DateTimeType namespace YourOwnApp\Doctrine;
class DateTimeImmutableType extends \Carbon\Doctrine\DateTimeImmutableType
{
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
{
$precision = $fieldDeclaration['precision'] ?? DateTimeDefaultPrecision::get();
$precision = min($precision, 6); // Ensure it's never more than 6
// Eventually 6 can be computed based on the maximum allowed by $platform
$type = parent::getSQLDeclaration($fieldDeclaration, $platform);
if (!$precision) {
return $type;
}
if (str_contains($type, '(')) {
return preg_replace('/\(\d+\)/', "($precision)", $type);
}
[$before, $after] = explode(' ', "$type ");
return trim("$before($precision) $after");
}
} |
BTW, that is an issue still open on DBAL side: Suggestion was to align on DBAL side the maximum precision with what the platform actually supports (instead of either 0 which by default truncate precision, or a constant value that as you can see will break in most platform). So I'm considering implementing on carbon types, but would be a shame because it would better fit in DBAL as it's also relevant for [EDIT] The branch can be tested with: |
So far in all debugging I guess because it's the default precision in doctrine dbal (maybe from here: https://github.com/doctrine/dbal/blob/3.7.x/src/Schema/Column.php#L25) but i have not confirmed this and i'm not that familiar with doctrine internals. I'll take some more time to debug further beginning next week. Thanks again for the suggestion incl. code examples, very much appreciated. |
It's not "because of that", if However we could cap the precision by the maximum that the platform support: You can test using the pull-request:
|
Released in carbonphp/carbon-doctrine-types 3.1.0, so simply update everything to latest will fix it. |
Could you release that fix for CarbonPHP/carbon-doctrine-types v2 ? I'm still on doctrine/dbal 3.7 and still have the problem. |
Yup, I can. May you try:
|
Works perfect! Thank you again, especially taking time over the weekend to work on this, you're awesome! |
Now released as 2.1.0. |
Hello,
since updating to 2.72 doctrine migrations are broken when using the doctrine types. From first investigations it uses the default doctrine column precision of 10 which is not supported for date/time columns (max. 6).
Error:
Carbon version: 2.72
PHP version: 8.3.0
MariaDB: 10.11.2-MariaDB-1:10.11.2+maria~ubu2204
Doctrine versions:
Downgrading to 2.71 solves the issue for me.
Unfortunately i'm short on time right now to debug further. In https://github.com/CarbonPHP/carbon-doctrine-types/blob/main/src/Carbon/Doctrine/CarbonTypeConverter.php#L38 the
$fieldDeclaration['precision']
is set to 10 which seems to be a doctrine default value as nowhere in my code the precision is defined.Thanks you very much for your time!
The text was updated successfully, but these errors were encountered: