Doctrine/DBAL Types::JSON
benblub opened this issue · 2 comments
Server Version
10.5.9-MariaDB
Entity
#[ORM\Column(type: Types::JSON)]
private array $roles = [];
auto-generated migration file
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE user ADD roles LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\'');
}
Problem
Existing rows create an empty string entry instead of [].
The problem is that LONGTEXT does not throw an error here. Only when the ORM wants to work with type array errors are thrown. It would be good to add at least one comment to the auto generate code.
Reproduce
add rows to an examble entity then add json field like in examble here.
Test json is not valid..
SELECT JSON_VALID(roles) FROM user
Solution
add comment, something like
// This is a json field, maybe existing fields needs to be updated
The SQL queries in the generated are coming from doctrine/dbal, not from doctrine/migrations (and even less from this bundle, which only provides the wiring of doctrine/migrations in a Symfony project)