[DBAL-504] DBAL Enum fields migration issue / PostgreSQL Created: 24/Apr/13  Updated: 03/Jan/14  Resolved: 03/Jan/14

Status: Resolved
Project: Doctrine DBAL
Component/s: Drivers, Schema Managers
Affects Version/s: 2.3.3
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: jos de witte Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 1
Labels: None
Environment:

postgresql


Issue Links:
Duplicate
is duplicated by DDC-2238 doctrine:schema:update partially broken Resolved

 Description   

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.



 Comments   
Comment by Tom Vogt [ 01/May/13 ]

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.

Comment by Benjamin Eberlei [ 04/May/13 ]

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

Comment by Tom Vogt [ 06/May/13 ]

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.

Comment by Steve Müller [ 29/Dec/13 ]

jos de witte Tom Vogt The truncated statement is most probably related to the column default value issue on PostgreSQL which should be fixed in this commit: https://github.com/doctrine/dbal/commit/8fe741053849afadef12b8bef1cc3203966ef78f
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.

Comment by Tom Vogt [ 30/Dec/13 ]

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 907f30dec77a9e83fdba8705fc642fd7815cbc11

) 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                       
---------------+------------------+-------------------------------------------------------
 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!

Comment by Steve Müller [ 30/Dec/13 ]

Tom Vogt 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.

Comment by Tom Vogt [ 30/Dec/13 ]

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.

Comment by Steve Müller [ 30/Dec/13 ]

Benjamin Eberlei can you resolve please? I cannot do that...

Generated at Tue Oct 21 21:52:56 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.