[DBAL-687] orm:schema-tool:update reports already updated NUMERIC fields Created: 14/May/13  Updated: 03/Jan/14  Resolved: 03/Jan/14

Status: Resolved
Project: Doctrine DBAL
Component/s: None
Affects Version/s: 2.3.4
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Francesco Montefoschi Assignee: Benjamin Eberlei
Resolution: Invalid Votes: 0
Labels: None
Environment:

PHP 5.3.10-1ubuntu3.6 with Suhosin-Patch (cli) (built: Mar 11 2013 14:31:48)
Mysql version: 5.5.31-0ubuntu0.12.04.1 (Ubuntu)



 Description   

I have a table defined in this way:

CREATE TABLE `my_table` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`subtotal` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

When I run
php doctrine.php orm:schema-tool:update --dump-sql

I get
ALTER TABLE my_table CHANGE subtotal subtotal NUMERIC(10, 2) DEFAULT NULL;

While of course the field is already updated. The same happens in SQL Server 2008 and Postgres 9.



 Comments   
Comment by Benjamin Eberlei [ 13/Dec/13 ]

The problem here is probably not the DECIMAL(10, 2), but the "NULL", which means that you have to define @ORM\Column(type="decimal precision=10, scale=22, nullable=true) with the "nullable=true". Did you do that?

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

Francesco Montefoschi Can you please verify that the fix from Benjamin Eberlei works? Otherwise can you please provide your mapping information? This indeed seems to be a mapping error.

Comment by Francesco Montefoschi [ 03/Jan/14 ]

I found the time to investigate. It is not related to NULL nor NOT NULL, neither to `decimal`.
The problem is that I created a new DBAL type, BcDecimal, which extends Doctrine\DBAL\Types\DecimalType.

The fields are annotated similarly to decimals, but type obiously is `bcdecimal`.
The new type is registered with `Type::addType`, everything works, except schema-tool:update which always reports these fields as changed.

Changing my annotations from `bcdecimal` to `decimal` removes the issue. Should we close this bug and create another one?

Comment by Steve Müller [ 03/Jan/14 ]

Francesco Montefoschi If you use custom types you have to overwrite the requiresSQLCommentHint() method to return true. Otherwise the schema manager will not be able to detect your custom type when introspecting from the database. Therefore the Comparator will compare like this: DecimalType == BcDecimal instead of BcDecimal == BcDecimal resulting in ALTER TABLE statements over and over again. Doctrine needs to detect you custom type mapping from the column comment, otherwise it will always set your column type to DecimalType again.
You can adopt this from here: https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Types/ObjectType.php#L76-L79

Comment by Francesco Montefoschi [ 03/Jan/14 ]

Thank you for your explanation. This issue can be closed.

Generated at Tue Jul 29 02:59:43 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.