[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

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)


I have a table defined in this way:

CREATE TABLE `my_table` (
`subtotal` decimal(10,2) DEFAULT NULL,

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.

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 Mon Aug 31 04:57:12 EDT 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.