Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-687

orm:schema-tool:update reports already updated NUMERIC fields

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 2.3.4
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • 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.

        Activity

        Francesco Montefoschi created issue -
        Steve Müller made changes -
        Field Original Value New Value
        Project Doctrine 2 - ORM [ 10032 ] Doctrine DBAL [ 10040 ]
        Key DDC-2448 DBAL-687
        Affects Version/s 2.3.4 [ 10421 ]
        Affects Version/s 2.3.4 [ 10420 ]
        Component/s Tools [ 10015 ]
        Security All [ 10000 ]
        Hide
        Benjamin Eberlei added a comment -

        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?

        Show
        Benjamin Eberlei added a comment - 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?
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Awaiting Feedback [ 10000 ]
        Hide
        Steve Müller added a comment -

        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.

        Show
        Steve Müller added a comment - 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.
        Hide
        Francesco Montefoschi added a comment -

        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?

        Show
        Francesco Montefoschi added a comment - 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?
        Hide
        Steve Müller added a comment -

        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

        Show
        Steve Müller added a comment - 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
        Hide
        Francesco Montefoschi added a comment -

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

        Show
        Francesco Montefoschi added a comment - Thank you for your explanation. This issue can be closed.
        Benjamin Eberlei made changes -
        Status Awaiting Feedback [ 10000 ] Open [ 1 ]
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Invalid [ 6 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DBAL-687, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Francesco Montefoschi
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: