Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-625

orm:schema-tool:update --dump-sql showing SQL when DB is up-to-date

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-BETA1
    • Fix Version/s: 2.0-BETA3
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      With the following entities ...

      <?php
      
      /**
       * @Entity
       * @Table(name="users")
       */
      class App_Model_User
      {
          /**
           * @Id
           * @GeneratedValue(strategy="IDENTITY")
           * @Column(type="integer")
           */
          private $id;
      
          /**
           * @ManyToOne(targetEntity="App_Model_Role")
           * @JoinColumn(name="role_id", nullable=false)
           */
          private $role;
      
          /** @Column(type="string", columnDefinition="CHAR(64) NOT NULL") */
          private $password;
      }
      
      <?php
      
      /**
       * @Entity
       * @Table(name="roles")
       */
      class App_Model_Role
      {
          /**
           * @Id
           * @GeneratedValue(strategy="IDENTITY")
           * @Column(type="smallint")
           */
          private $id;
      }

      I'm getting this output from orm:schema-tool:update --dump-sql, when the database is already up-to-date:

      ALTER TABLE users CHANGE password password CHAR(64) NOT NULL;
      ALTER TABLE users DROP FOREIGN KEY users_ibfk_1;
      ALTER TABLE users ADD FOREIGN KEY (role_id) REFERENCES roles(id)

        Activity

        Hide
        Christian Heinrich added a comment -

        This is most probably equivalent with the following problem:

        It's got to do with cli: when you DB is up to date and you run orm:schema-tool:update --dump-sql, you get something like this:

        ALTER TABLE user_users CHANGE avatar avatar LONGTEXT NOT NULL <- but the column avatar is already LONGTEXT

        This is caused by the following: Two schema objects are being compared. The first schema is created from the current mapping files (YAML, e.g.) and within these, this column is marked as "object". When the DB is setup, object is transferred into another type, like LONGTEXT. (Platform dependent)

        The second schema is created from your current database and is marked as "TextType" because Doctrine cannot decide which other type - there are several who use LONGTEXT - would be correct

        See /DBAL/Schema/Comparator.php ll. 172ff. & 293

        Comparing whether both Types return the same SQL-Statement might do the job but would be really ugly.

        Show
        Christian Heinrich added a comment - This is most probably equivalent with the following problem: It's got to do with cli: when you DB is up to date and you run orm:schema-tool:update --dump-sql, you get something like this: ALTER TABLE user_users CHANGE avatar avatar LONGTEXT NOT NULL <- but the column avatar is already LONGTEXT This is caused by the following: Two schema objects are being compared. The first schema is created from the current mapping files (YAML, e.g.) and within these, this column is marked as "object". When the DB is setup, object is transferred into another type, like LONGTEXT. (Platform dependent) The second schema is created from your current database and is marked as "TextType" because Doctrine cannot decide which other type - there are several who use LONGTEXT - would be correct See /DBAL/Schema/Comparator.php ll. 172ff. & 293 Comparing whether both Types return the same SQL-Statement might do the job but would be really ugly.
        Hide
        Benjamin Eberlei added a comment -

        The columnDefintion affected field can obviously not be solved by any means.

        The foreign key thing i see more often in my own projects though, i have to dig deeper there.

        Show
        Benjamin Eberlei added a comment - The columnDefintion affected field can obviously not be solved by any means. The foreign key thing i see more often in my own projects though, i have to dig deeper there.
        Hide
        Benjamin Eberlei added a comment -

        Fixed Foreign Key issue in DBAL master, it was an error in the MySQL query to fetch the foreign keys.

        Show
        Benjamin Eberlei added a comment - Fixed Foreign Key issue in DBAL master, it was an error in the MySQL query to fetch the foreign keys.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Glen Ainscow
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: