fre5h / DoctrineEnumBundle

📦 Provides support of ENUM type for Doctrine in Symfony applications.
https://github.com/fre5h/DoctrineEnumBundle
MIT License
460 stars 75 forks source link

doctrine:migrations:diff always regenerates enum ALTER on mariadb #228

Open ahmed-bhs opened 1 year ago

ahmed-bhs commented 1 year ago

I am using symfony/* v5.4.23 and a mariadb database v10.5.15. I have the following problem every time I run console doctrine:migrations:diff. The output always regenerates an ALTER on the enum field.

Here is an example output:


final class Version20230512083413 extends AbstractMigration
{
    public function up(Schema $schema): void
    {
        $this->addSql('ALTER TABLE catalog_product CHANGE publication_status publication_status ENUM(\'pending\', \'published\', \'deleted\') DEFAULT \'pending\' NOT NULL COMMENT \'(DC2Type:enum_status)\'');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE catalog_product CHANGE publication_status publication_status ENUM(\'pending\', \'published\', \'deleted\') DEFAULT \'pending\' DEFAULT \'pending\' NOT NULL COMMENT \'(DC2Type:enum_status)\'');
    }
}

This is my EnumType:

final class EnumStatusType extends AbstractEnumType
{
    public const STATUS_PENDING = 'pending';
    public const STATUS_PUBLISHED = 'published';
    public const STATUS_DELETED = 'deleted';

    protected static array $choices = [
        self::STATUS_PENDING => 'pending',
        self::STATUS_PUBLISHED => 'published',
        self::STATUS_DELETED => 'deleted',
    ];

    public static function getDefaultValue(): string
    {
        return self::STATUS_PENDING; // This value will be used as default in DDL statement
    }
}

This is my doctrine config:

doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'
        # DATABASE_URL=mysql://root:root@mariadb:3306/test?serverVersion=mariadb-10.5.15
        types:
            enum_status: App\Doctrine\DBAL\Types\EnumStatusType
    orm:
        auto_generate_proxy_classes: true
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

This is my entity property:

class CatalogProduct {
{
    /**
     * @var string
     *
     * @Assert\NotBlank()
     * @DoctrineAssert\Enum(entity="App\Doctrine\DBAL\Types\EnumStatusType")
     *
     * @ORM\Column(type="enum_status", nullable=false)
     */
    private $publicationStatus;

And finally, this is a quick scope about my current dependencies versions:

doctrine/dbal 3.6.2 doctrine/doctrine-migrations-bundle 3.2.2
doctrine/migrations 3.5.5
fresh/doctrine-enum-bundle v7.4.0

Any help would be appreciated.