BC: Extract EnumType from comment hint is broken !
meiyasan opened this issue · 2 comments
Bug Report
Q | A |
---|---|
Version | 4.0.0 |
Summary
I was used to create EnumType using a EnumSubscriber::postGenerateSchema
; This subscriber was using CommentHint. This has been removed from dbal in the commit 4134b86cb986f6fc68fe9ba7c8a7416debfa22bd
.
<?php
namespace App\DatabaseSubscriber;
use App\Database\Type\EnumType;
use Doctrine\DBAL\Schema\Column;
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
class EnumSubscriber
{
public function postGenerateSchema(GenerateSchemaEventArgs $eventArgs)
{
$columns = [];
foreach ($eventArgs->getSchema()->getTables() as $table) {
foreach ($table->getColumns() as $column) {
if ($column->getType() instanceof EnumType) {
$columns[] = $column;
}
}
}
/** @var Column $column */
foreach ($columns as $column) {
$enum = $column->getType();
$column->setComment(trim(sprintf('%s (%s)', $column->getComment(), implode(',', $enum::getPermittedValues()))));
}
}
}
Current behaviour
Current behavior, makes db schema update infinitely refreshing.
How to reproduce
Just create a EnumType following; and use postGenerateSchema
subscriber.
Expected behaviour
I would expect to restore in AbstractSchemaManager.php
:
public function removeDoctrineTypeFromComment($comment, $type)
public function extractDoctrineTypeFromComment($comment, $currentType)
Then restore on every platform,
$type = $this->platform->getDoctrineTypeMapping($dbType);
// 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);
}
Unless this was suppressed on purpose, it was very useful feature to incorporate EnumType.
If an alternative is possible, please advice.
Here is an attempt of pull request, that fixes my issues implementing EnumType
#6444
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.