orm:schema-tool:update tries to change columns without changes #5151

Closed
opened 2026-01-22 14:59:47 +01:00 by admin · 2 comments
Owner

Originally created by @DASPRiD on GitHub (Jun 11, 2016).

While working a little with custom types in Doctrine lately, I recently noticed a bug in the Comparator, although its roots are deeper down. Consider having a custom type like this:

class CustomType extends Type
{
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
    {
        return $platform->getBinaryTypeDeclarationSQL([
            'length' => '16',
            'fixed' => true,
        ]);
    }

    public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        // …
    }

    public function convertToPHPValue($value, AbstractPlatform $platform)
    {
        // …
    }

    public function requiresSQLCommentHint(AbstractPlatform $platform)
    {
        return true;
    }

    public function getName()
    {
        return 'CustomType';
    }
}

Now, when using that type in an entity, at first when generating the database SQL and inserting it, everything is fine. The column has the correct type (binary, fixed 16) and a comment denoting the "CustomType" type.

The problem now is when asking the schema-tool for a diff. Even though the column using that type wasn't changed, the schema-tool suggests an ALTER TABLE statement, changing the column to exactly what it already is.

I looked a bit into this, and it seems that the problem is that the Schema generated from the mapping files does not include the columns comment, length, fixed status and also that the type in the Schema coming from the DB has Binary as type, instead of CustomType. This lets the Comparator think it needs to update the column.

This problem looks rather complex to me, and I have no real idea on how to solve this, maybe someone else who has a better insight can analyse this further.

Originally created by @DASPRiD on GitHub (Jun 11, 2016). While working a little with custom types in Doctrine lately, I recently noticed a bug in the `Comparator`, although its roots are deeper down. Consider having a custom type like this: ``` php class CustomType extends Type { public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return $platform->getBinaryTypeDeclarationSQL([ 'length' => '16', 'fixed' => true, ]); } public function convertToDatabaseValue($value, AbstractPlatform $platform) { // … } public function convertToPHPValue($value, AbstractPlatform $platform) { // … } public function requiresSQLCommentHint(AbstractPlatform $platform) { return true; } public function getName() { return 'CustomType'; } } ``` Now, when using that type in an entity, at first when generating the database SQL and inserting it, everything is fine. The column has the correct type (binary, fixed 16) and a comment denoting the "CustomType" type. The problem now is when asking the schema-tool for a diff. Even though the column using that type wasn't changed, the schema-tool suggests an ALTER TABLE statement, changing the column to exactly what it already is. I looked a bit into this, and it seems that the problem is that the `Schema` generated from the mapping files does not include the columns comment, length, fixed status and also that the type in the `Schema` coming from the DB has `Binary` as type, instead of `CustomType`. This lets the `Comparator` think it needs to update the column. This problem looks rather complex to me, and I have no real idea on how to solve this, maybe someone else who has a better insight can analyse this further.
admin closed this issue 2026-01-22 14:59:47 +01:00
Author
Owner

@beberlei commented on GitHub (Jun 12, 2016):

@DASPRiD This is a DBAL issue, please re-open the ticket there.

@beberlei commented on GitHub (Jun 12, 2016): @DASPRiD This is a DBAL issue, please re-open the ticket there.
Author
Owner

@DASPRiD commented on GitHub (Jun 12, 2016):

Re-created the issue under doctrine/dbal: https://github.com/doctrine/dbal/issues/2411

@DASPRiD commented on GitHub (Jun 12, 2016): Re-created the issue under doctrine/dbal: https://github.com/doctrine/dbal/issues/2411
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5151