postgresql-for-doctrine icon indicating copy to clipboard operation
postgresql-for-doctrine copied to clipboard

jsonb type is interpreted as json in doctrine migrations

Open vbourdeix opened this issue 5 years ago • 6 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 ?

vbourdeix avatar Jun 09 '20 16:06 vbourdeix

Sounds like something is missing from the configuration. Can you share your setup, please?

martin-georgiev avatar Jul 08 '20 16:07 martin-georgiev

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 ?

vbourdeix avatar Jul 08 '20 17:07 vbourdeix

Did you find what's the problem?

martin-georgiev avatar Jan 23 '21 23:01 martin-georgiev

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 

Aweptimum avatar Mar 22 '22 14:03 Aweptimum

Oh interesting !

That's pretty old so I can't remember how I handled it but I'll try to take a look again and try that soon.

Thanks 👍

Le mar. 22 mars 2022 à 15:41, Sam @.***> a écrit :

I tried reproducing this behavior while installing the package. Noticed that the mapping_types section is missing from @vbourdeix https://github.com/vbourdeix's doctrine config, so I omitted it and the migration does indeed default to json. Adding the following to doctrine.yaml fixes it

dbal:
    mapping_types:
        jsonb: jsonb

— Reply to this email directly, view it on GitHub https://github.com/martin-georgiev/postgresql-for-doctrine/issues/71#issuecomment-1075268620, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAB4AGILDII6O6XJF2OCXNLVBHL2NANCNFSM4NZRRMVQ . You are receiving this because you were mentioned.Message ID: @.***>

vbourdeix avatar Oct 11 '22 07:10 vbourdeix