Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsonb type is interpreted as json in doctrine migrations #71

Open
vbourdeix opened this issue Jun 9, 2020 · 6 comments
Open

jsonb type is interpreted as json in doctrine migrations #71

vbourdeix opened this issue Jun 9, 2020 · 6 comments

Comments

@vbourdeix
Copy link

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 ?

@martin-georgiev
Copy link
Owner

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

@vbourdeix
Copy link
Author

vbourdeix commented Jul 8, 2020

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 ?

@martin-georgiev
Copy link
Owner

Did you find what's the problem?

@Aweptimum
Copy link

Aweptimum commented Mar 22, 2022

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 

@vbourdeix
Copy link
Author

vbourdeix commented Oct 11, 2022 via email

@adrianrudnik
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants