Skip to content

Loading…

DBAL-504: DBAL Enum fields migration issue / PostgreSQL #1708

Closed
doctrinebot opened this Issue · 10 comments

2 participants

@doctrinebot

Jira issue originally created by user josdewitte:

When using Custom Doctrine DBAL Enums the migration created using diff

works fine the first time.

However the next time it generates a SQL statement trying to change to field type to INT from integer; (Redundant)
and a truncated statement:

"ALTER schemaname.fieldname SET" .. And that's it.

@doctrinebot

Comment created by tom:

Doesn't only happen on Enums. I don't use any enums and I have this problem. I use a couple of geo (postGIS) fields (point, linestring, polygon) as well as array fields, so either or all of those might be causing it, too.

@doctrinebot

Comment created by @beberlei:

We did some changes for PostgreSQL column diffs lately, can you verify this bug still exists on the 2.3 Branch of DBAL?

@doctrinebot

Comment created by tom:

I'm running this on Symfony2 with this composer.json config:

    "doctrine/orm": "2.3.*",
    "doctrine/doctrine-bundle": ">=2.1",

and I'm still getting this issue today.

@doctrinebot

Comment created by @deeky666:

[josdewitte] [tom] The truncated statement is most probably related to the column default value issue on PostgreSQL which should be fixed in this commit: 8fe7410
Can you please again check if this still exists in the current master branch.
If it still exists please provide your mapping information and the changes that cause wrong SQL. Thank you.

@doctrinebot

Comment created by tom:

Quick check after updating (composer says my versions are now:

  • Updating doctrine/doctrine-bundle dev-master (2ed4639 => c65e5a2)
    Checking out c65e5a21d1db794511d11fe28918f41bd6072f8f

  • Updating doctrine/dbal 2.3.x-dev (59c310b => 907f30d)
    Checking out 907f30d

) still shows the error happening, but I've only run an update --dump-sql and didn't init a new database or anything.

here's my mapping for one entity that causes this:

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping>
    <entity name="BM2\SiteBundle\Entity\Building">
        <id name="id" type="integer">
            <generator strategy="IDENTITY"/>
        </id>
        <field name="workers" type="float"/>
        <field name="active" type="boolean"/>
        <field name="condition" type="integer"/>
        <field name="resupply" type="integer"/>
        <field name="current_speed" type="float"/>

        <many-to-one field="settlement" target-entity="Settlement" inversed-by="buildings"/>
        <many-to-one field="type" target-entity="BuildingType" inversed-by="buildings"/>

    </entity>
</doctrine-mapping>

and on " php app/console doctrine:schema:update --dump-sql" I get for this entity:

ALTER TABLE building ALTER current_speed SET ;

I do think it is related to the default column indeed, as adding this to an existing database required me to add it with a default value that is not reflected in the mapping data, so the current column definition for this entity is:

                                 Table "public.building"
    Column     |       Type       |                       Modifiers                       
---------------<ins>------------------</ins>-------------------------------------------------------
 id            | integer          | not null default nextval('building*id*seq'::regclass)
 settlement_id | integer          | 
 type_id       | integer          | 
 workers       | double precision | not null
 active        | boolean          | not null
 condition     | integer          | not null
 resupply      | integer          | not null
 current_speed | double precision | not null default 1.0

and if I drop the default (alter table building alter current_speed drop default) then the problem disappears. So at least there's a workaround now, thanks!

@doctrinebot

Comment created by @deeky666:

[~tom] The problem is composer installed from DBAL 2.3-dev branch. But the patch is currently only available in DBAL master. You have to test this with the current DBAL master somehow.

@doctrinebot

Comment created by tom:

confirmed fixed:

Updating dependencies (including require-dev)                          
  - Updating doctrine/dbal (2.3.x-dev 907f30d => dev-master 9ec63e2)
    Checking out 9ec63e25b572db79c09cacccb844e33ed435e479

  - Updating doctrine/orm (2.3.x-dev 1a30e0a => dev-master 58c57c5)
    Checking out 58c57c50bf3582a1672bc09733afab4167ebd5ba
php app/console doctrine:generate:entities BM2 --no-backup
...
ALTER TABLE settlement ALTER starvation DROP DEFAULT;
...

it is now correctly updating.

Thanks.

@doctrinebot

Comment created by @deeky666:

[~beberlei] can you resolve please? I cannot do that...

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added the Bug label
@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.