jsonb type is interpreted as json in doctrine migrations
vbourdeix opened this issue · comments
When creating an entity with a jsonb field and generating a migration with doctrine migrations, the migration defines the field as JSON, which forces me to fix that mannually each time I create a migration.
Do you have a way to fix this ?
Sounds like something is missing from the configuration. Can you share your setup, please?
Here is my config/packages/doctrine.yaml :
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_pgsql'
charset: utf8
default_table_options:
charset: utf8
collate: en_US.UTF-8
url: '%env(resolve:DATABASE_URL)%'
types:
jsonb: MartinGeorgiev\Doctrine\DBAL\Types\Jsonb
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
dql:
string_functions:
ILIKE: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Ilike
CONTAINS: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Contains
JSON_GET_FIELD: MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\JsonGetField
And here is a typical field definition inside my entity :
/**
* @ORM\Column(type="jsonb", nullable=true)
*/
private $test = [];
Did I miss something ?
Did you find what's the problem?
I tried reproducing this behavior while installing the package. Noticed that the mapping_types
section is missing from @vbourdeix's doctrine config, so I omitted it and the migration does indeed default to json. Adding the following to doctrine.yaml
fixes it
doctrine:
dbal:
mapping_types:
jsonb: jsonb
Had something similar with JSONB columns always showing up in migrations, with a simple fix for posterity:
Don't do
#[ORM\Column(type: 'json', options: ['jsonb' => true])]
do
#[ORM\Column(type: 'jsonb')]
Or the DBAL JSON type will always be compared to the JSON type here and generate a diff.