doctrine / dbal

Doctrine Database Abstraction Layer
https://www.doctrine-project.org/projects/dbal.html
MIT License
9.46k stars 1.33k forks source link

PostgreSQL jsonb column is ignored by update tool. #4155

Open remoteclient opened 4 years ago

remoteclient commented 4 years ago

Bug Report

Q A
BC Break no
Version 2.10.2

Summary

I have a entity with several jsonb columns:

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                                      http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
                  xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
>

    <entity name="MWS\NutritionCalculatorBundle\Entity\Recipe"
            table="mws_nc_recipe"
            repository-class="MWS\NutritionCalculatorBundle\Repository\RecipeRepository"
    >
...
        <field name="recipePetJson" type="json" column="recipe_pet_json" nullable="false">
            <options>
                <option name="jsonb">true</option>
            </options>
        </field>
        <field name="recipeItemsJson" type="json" column="recipe_items_json" nullable="false">
            <options>
                <option name="jsonb">true</option>
            </options>
        </field>
        <field name="analysisJson" type="json" column="analysis_json" nullable="false">
            <options>
                <option name="jsonb">true</option>
            </options>
        </field>
        <field name="requirementJson" type="json" column="requirement_json" nullable="false">
            <options>
                <option name="jsonb">true</option>
            </options>
        </field>
...

    </entity>
</doctrine-mapping>

Current behaviour

I got the columns update by doing: php bin/console doctrine:schema:update --dump-sql

After the update, the update tools output is still:

     ALTER TABLE mws_nc_recipe ALTER recipe_pet_json TYPE JSONB;
     ALTER TABLE mws_nc_recipe ALTER recipe_pet_json DROP DEFAULT;
     ALTER TABLE mws_nc_recipe ALTER recipe_items_json TYPE JSONB;
     ALTER TABLE mws_nc_recipe ALTER recipe_items_json DROP DEFAULT;
     ALTER TABLE mws_nc_recipe ALTER analysis_json TYPE JSONB;
     ALTER TABLE mws_nc_recipe ALTER analysis_json DROP DEFAULT;
     ALTER TABLE mws_nc_recipe ALTER requirement_json TYPE JSONB;
     ALTER TABLE mws_nc_recipe ALTER requirement_json DROP DEFAULT;

I set the Postgres Version in my .env file:

SERVER_VERSION=12
DATABASE_DRIVER=pdo_pgsql
DATABASE_HOST=xxxxxx
DATABASE_NAME=xxxxxx
DATABASE_USER=xxxxxx
DATABASE_PASSWORD=xxxxxx

This is imported in doctrine.yaml file:

doctrine:
    dbal:
        #url: '%env(DATABASE_URL)%'
        server_version: '%env(SERVER_VERSION)%'
        driver:   '%database_driver%'
        host:     '%database_host%'
        dbname:   '%database_name%'
        user:     '%database_user%'
        password: '%database_password%'

Expected behaviour

Once the columns are update, the schema tool should indicate that it is in sync with database

Tobion commented 3 years ago

Duplicate of #2541