doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.92k stars 2.51k forks source link

EnumType issue after upgrade #11503

Closed xkzl closed 3 months ago

xkzl commented 3 months ago

Bug Report

Q A
BC Break yes
Version 3.2.0

Summary

I am investigating an issue with custom EnumType definition in MySQL. I have defined an EnumType following Doctrine predicates quite some time ago; now that I upgraded to the last version of ORM. When I try to upgrade the database, I get a different db schema.

Current behavior

$ php bin/console doctrine:schema:update --dump-sql --force -vvv
1^ Doctrine\DBAL\Schema\ColumnDiff^ {#9492
  -oldColumn: Doctrine\DBAL\Schema\Column^ {#9471
    #_name: "action"
    #_namespace: null
    #_quoted: false
    #_type: Doctrine\DBAL\Types\StringType^ {#412}
    #_length: 0
    #_precision: null
    #_scale: 0
    #_unsigned: false
    #_fixed: false
    #_notnull: true
    #_default: null
    #_autoincrement: false
    #_platformOptions: []
    #_columnDefinition: null
    #_comment: "(DC2Type:enum,entity_action)"
  }
  -newColumn: Doctrine\DBAL\Schema\Column^ {#9447
    #_name: "action"
    #_namespace: null
    #_quoted: false
    #_type: Base\Enum\EntityAction^ {#476}
    #_length: null
    #_precision: null
    #_scale: 0
    #_unsigned: false
    #_fixed: false
    #_notnull: true
    #_default: null
    #_autoincrement: false
    #_platformOptions: array:1 [
      "version" => false
    ]
    #_columnDefinition: null
    #_comment: "(DC2Type:enum,entity_action)"
  }
}
2^ array:1 [
  0 => "CHANGE action action ENUM('ACTION_DELETE', 'ACTION_INSERT', 'ACTION_UPDATE') NOT NULL COMMENT '(DC2Type:enum,entity_action)'"
]

The ALTER line rendered is the following: ALTER TABLE extensionAbstract CHANGE action action ENUM('ACTION_DELETE', 'ACTION_INSERT', 'ACTION_UPDATE') NOT NULL COMMENT 'ENUM(ACTION_DELETE, ACTION_INSERT, ACTION_UPDATE)';

I am suspecting the change might be due to some modification in ./vendor/doctrine/dbal/src/Schema/MySQLSchemaManager.php; the following line has been modified.

        // In cases where not connected to a database DESCRIBE $table does not return 'Comment'
        if (isset($tableColumn['comment'])) {
            $type                   = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type);
            $tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type);
        }

How to fix it ?

Expected behavior

Looking at the expected behavior from earlier version, I get should get: #_type: Base\Enum\EntityAction^ {#476} in the db schema, but it returns stringType

xkzl commented 3 months ago

wrong repo, I just opened a new discussion here: https://github.com/doctrine/dbal/issues/6443