Skip to content

Loading…

DBAL-687: orm:schema-tool:update reports already updated NUMERIC fields #1908

Closed
doctrinebot opened this Issue · 6 comments

2 participants

@doctrinebot

Jira issue originally created by user osvi:

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.

@doctrinebot

Comment created by @beberlei:

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?

@doctrinebot

Comment created by @deeky666:

[osvi] Can you please verify that the fix from [beberlei] works? Otherwise can you please provide your mapping information? This indeed seems to be a mapping error.

@doctrinebot

Comment created by osvi:

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?

@doctrinebot

Comment created by @deeky666:

[~osvi] 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

@doctrinebot

Comment created by osvi:

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

@doctrinebot

Issue was closed with resolution "Invalid"

@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.