Skip to content

Migration does not detect custom SQLDeclaration change #5308

Open
@michnovka

Description

Bug Report

If declaring custom Type and its getSQLDeclaration() method changes, no migration is generated.

Q A
Version 3.3.2

Summary

Implement ENUM like in the official docs Then if you add/remove new ENUM element, the return value of getSQLDeclaration() changes. But this is not detected by Comparer and no migration is generated

How to reproduce

Create type:

<?php
namespace MyProject\DBAL;

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;

class EnumVisibilityType extends Type
{
    const ENUM_VISIBILITY = 'enumvisibility';
    const STATUS_VISIBLE = 'visible';
    const STATUS_INVISIBLE = 'invisible';

    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
    {
        return "ENUM('visible', 'invisible')";
    }

    public function convertToPHPValue($value, AbstractPlatform $platform)
    {
        return $value;
    }

    public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        if (!in_array($value, array(self::STATUS_VISIBLE, self::STATUS_INVISIBLE))) {
            throw new \InvalidArgumentException("Invalid status");
        }
        return $value;
    }

    public function getName()
    {
        return self::ENUM_VISIBILITY;
    }

    public function requiresSQLCommentHint(AbstractPlatform $platform)
    {
        return true;
    }
}
  1. Create Entity with column of this type
<?php
/** @Entity */
class Article
{
    /** @Column(type="enumvisibility") */
    private $status;
}
  1. Migrate and save DB schema change.
  2. Change getSQLDeclaration to
        return "ENUM('visible', 'invisible','halfvisible')";
  1. Do migrations:diff

Expected behaviour

New migration is created reflecting the change

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