Skip to content

Changing precision/scale value has no effect in schema comparison when not extendend from DecimalType #4981

Open
@gregor-tb

Description

@gregor-tb

Bug Report

Q A
BC Break no
Version 3.1.3

Summary

We have a custom "money_value" type, to set decimal with predefined values for precision + scale like numeric(10,4). This works on first migration, but changes (e.g. to 11,4) are not recognized.

The type class looks like this:

class MoneyValueType extends ApplicationDoctrineType
{
    public const NAME = 'money_value';

    /**
     * {@inheritdoc}
     */
    public function getSQLDeclaration(array $column, AbstractPlatform $platform)
    {
        $column['precision'] = 11;
        $column['scale'] = 4;

        return $platform->getDecimalTypeDeclarationSQL($column);
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return self::NAME;
    }
}

This should do it, SQL declaration returns numeric(11,4)... But DBAL has a trap in Comparator.php:

} elseif ($properties1['type'] instanceof Types\DecimalType) {
if (($properties1['precision'] ?? 10) !== ($properties2['precision'] ?? 10)) {
$changedProperties[] = 'precision';
}
if ($properties1['scale'] !== $properties2['scale']) {
$changedProperties[] = 'scale';
}
}

The documentation does not require to extend specific Type classes (https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#custom-mapping-types).

If precision and scale are irrelevant for non-decimal types, they should not have default values at all and the magic "10" should be set in DecimalType.

There is a similar problem with fixed as well.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions