Doctrine Schema Update issue
michelsalib opened this issue · 8 comments
Currently, the schema tool for doctrine is suggesting an update of the enum columns when there is no need to.
Do you know where it comes from ?
Yeah, i've seen this behavior when using the migrations.
I think the reason is that missing comment which should contains the type name in the column definition for the custom types. When you use the native type of ORM (array, for example) comment will be added to the column definition: foo LONGTEXT DEFAULT NULL COMMENT '(DC2Type:array)'
I tied to add the comment to my db field and it did not solved it... So I dig into the shema tool and foud that the schema extractor found Doctrine\DBAL\Types\TextType
where the annotation extractor found My\MyEnum
.
I found nothing more so far.
Oups, sorry, I mixed my dev and test db. You are perfectly right, the comment fixes everything. I continue to search if I can inject it.
You can tries override getSQLDeclaration
method. Through this method can be overridden the column definition for your type. For example:
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getIntegerTypeDeclarationSQL($fieldDeclaration) . ' ' . $platform->getDoctrineTypeComment($this);
}
I have not tried it in practice, but maybe it will solve your problem.
Thanks for the tip. That's was almost right. Here is the right fix :
<?php
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getIntegerTypeDeclarationSQL($fieldDeclaration) . ' COMMENT \'' . $platform->getDoctrineTypeComment($this).'\'';
}
What do you think about providing a base class for DoctrineType ? This the things will bu more transparent for users.
I would be glad to make a commit :)
I think, there is another solution, to mark the custom type as the commented doctrine type. We can use this method https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php#L307
I will try in the near future make a PR for Symfony, so that all types defined in the configuration will be marked as the commented doctrine type. It should resolve this problem for all custom types :)
Ok, I look forward to it :)