Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1137

SchemaTool#getUpdateSchemaSql() does not respect database identifier in table names

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0.4
    • Fix Version/s: None
    • Component/s: ORM, Tools
    • Security Level: All
    • Labels:
      None
    • Environment:
      Linux 2.6.18-194.32.1.el5.centos.plus x86_64 GNU/Linux

      Description

      Given two databases, 'foo' and 'bar', with entities in /Entities/Foo/ annotated as follows:

      /**
       * Test
       *
       * @Table(name="foo.test")
       * @Entity
       */
      

      Create an EntityManager instance with

      $connectionOptions = array( 
          'dbname' => 'Foo', 
          'driver' => 'pdo_mysql', 
          <..etc..>
      );

      Use EntityManager#getClassMetaData( "Entities\\Foo
      Test" ) to pass to SchemaTool#createSchema() and Doctrine appropriately creates a database table foo.test

      Use EntityManager#getClassMetaData( "Entities\\Foo
      Test" ) to pass to SchemaTool#updateSchema() and Doctrine fails with Exception
      -> SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'test' already exists

      Inserting

      die( print_r( $fromSchema, 1 ) . print_r( $toSchema, 1 ) . print_r( $schemaDiff, 1 ) );

      into Doctrine/ORM/Tools/SchemaTool.php line 632 shows $fromSchema outputs

      [_tables:protected] => Array
              (
                  [test]

      but $toSchema outputs

      [_tables:protected] => Array
              (
                  [foo.test]

      which causes $schemaDiff to output

      [newTables] => Array
              (
                  [foo.test]

      In summary, Doctrine/DBAL/Schema/Comparator considers foo.test a new table, because Doctrine/DBAL/Schema/AbstractSchemaManager lists its table as "test" rather than "foo.test".

        Activity

        Hugh Lomas created issue -
        Hugh Lomas made changes -
        Field Original Value New Value
        Description Given two databases, 'foo' and 'bar', with entities in /Entities/Foo/ annotated as follows:

        /**
         * Test
         *
         * @Table(name="foo.test")
         * @Entity
         */

        Create an EntityManager instance with $connectionOptions( 'dbname' => 'Foo', 'driver' => 'pdo_mysql', <..etc..>);

        Use EntityManager#getClassMetaData( "Entities\\Foo\\Test" ) to pass to SchemaTool#createSchema() and Doctrine appropriately creates a database table foo.test

        Use EntityManager#getClassMetaData( "Entities\\Foo\\Test" ) to pass to SchemaTool#updateSchema() and Doctrine fails with Exception
        -> SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'test' already exists

        Inserting
             die( print_r( $fromSchema, 1 ) . print_r( $toSchema, 1 ) . print_r( $schemaDiff, 1 ) );
        into Doctrine/ORM/Tools/SchemaTool.php line 632 shows $fromSchema outputs

          [_tables:protected] => Array
                (
                    [test]

        but $toSchema outputs

          [_tables:protected] => Array
                (
                    [foo.test]

        which causes $schemaDiff to output

         [newTables] => Array
                (
                    [foo.test]


        In summary, Doctrine/DBAL/Schema/Comparator considers foo.test a new table, because Doctrine/DBAL/Schema/AbstractSchemaManager lists its table as "test" rather than "foo.test".

        Given two databases, 'foo' and 'bar', with entities in /Entities/Foo/ annotated as follows:
        {noformat}
        /**
         * Test
         *
         * @Table(name="foo.test")
         * @Entity
         */
        {noformat}
        Create an EntityManager instance with
        {noformat}$connectionOptions( 'dbname' => 'Foo', 'driver' => 'pdo_mysql', <..etc..>);{noformat}
        Use EntityManager#getClassMetaData( "Entities\\Foo\\Test" ) to pass to SchemaTool#createSchema() and Doctrine appropriately creates a database table foo.test

        Use EntityManager#getClassMetaData( "Entities\\Foo\\Test" ) to pass to SchemaTool#updateSchema() and Doctrine fails with Exception
        -> SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'test' already exists

        Inserting
        {noformat}die( print_r( $fromSchema, 1 ) . print_r( $toSchema, 1 ) . print_r( $schemaDiff, 1 ) );{noformat}
        into Doctrine/ORM/Tools/SchemaTool.php line 632 shows $fromSchema outputs
        {noformat}[_tables:protected] => Array
                (
                    [test]{noformat}

        but $toSchema outputs

        {noformat}[_tables:protected] => Array
                (
                    [foo.test]{noformat}

        which causes $schemaDiff to output

        {noformat}[newTables] => Array
                (
                    [foo.test]{noformat}

        In summary, Doctrine/DBAL/Schema/Comparator considers foo.test a new table, because Doctrine/DBAL/Schema/AbstractSchemaManager lists its table as "test" rather than "foo.test".

        Hugh Lomas made changes -
        Description Given two databases, 'foo' and 'bar', with entities in /Entities/Foo/ annotated as follows:
        {noformat}
        /**
         * Test
         *
         * @Table(name="foo.test")
         * @Entity
         */
        {noformat}
        Create an EntityManager instance with
        {noformat}$connectionOptions( 'dbname' => 'Foo', 'driver' => 'pdo_mysql', <..etc..>);{noformat}
        Use EntityManager#getClassMetaData( "Entities\\Foo\\Test" ) to pass to SchemaTool#createSchema() and Doctrine appropriately creates a database table foo.test

        Use EntityManager#getClassMetaData( "Entities\\Foo\\Test" ) to pass to SchemaTool#updateSchema() and Doctrine fails with Exception
        -> SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'test' already exists

        Inserting
        {noformat}die( print_r( $fromSchema, 1 ) . print_r( $toSchema, 1 ) . print_r( $schemaDiff, 1 ) );{noformat}
        into Doctrine/ORM/Tools/SchemaTool.php line 632 shows $fromSchema outputs
        {noformat}[_tables:protected] => Array
                (
                    [test]{noformat}

        but $toSchema outputs

        {noformat}[_tables:protected] => Array
                (
                    [foo.test]{noformat}

        which causes $schemaDiff to output

        {noformat}[newTables] => Array
                (
                    [foo.test]{noformat}

        In summary, Doctrine/DBAL/Schema/Comparator considers foo.test a new table, because Doctrine/DBAL/Schema/AbstractSchemaManager lists its table as "test" rather than "foo.test".

        Given two databases, 'foo' and 'bar', with entities in /Entities/Foo/ annotated as follows:
        {noformat}
        /**
         * Test
         *
         * @Table(name="foo.test")
         * @Entity
         */
        {noformat}
        Create an EntityManager instance with
        {noformat}$connectionOptions = array(
            'dbname' => 'Foo',
            'driver' => 'pdo_mysql',
            <..etc..>
        );{noformat}
        Use EntityManager#getClassMetaData( "Entities\\Foo\\Test" ) to pass to SchemaTool#createSchema() and Doctrine appropriately creates a database table foo.test

        Use EntityManager#getClassMetaData( "Entities\\Foo\\Test" ) to pass to SchemaTool#updateSchema() and Doctrine fails with Exception
        -> SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'test' already exists

        Inserting
        {noformat}die( print_r( $fromSchema, 1 ) . print_r( $toSchema, 1 ) . print_r( $schemaDiff, 1 ) );{noformat}
        into Doctrine/ORM/Tools/SchemaTool.php line 632 shows $fromSchema outputs
        {noformat}[_tables:protected] => Array
                (
                    [test]{noformat}

        but $toSchema outputs

        {noformat}[_tables:protected] => Array
                (
                    [foo.test]{noformat}

        which causes $schemaDiff to output

        {noformat}[newTables] => Array
                (
                    [foo.test]{noformat}

        In summary, Doctrine/DBAL/Schema/Comparator considers foo.test a new table, because Doctrine/DBAL/Schema/AbstractSchemaManager lists its table as "test" rather than "foo.test".

        Hide
        Hugh Lomas added a comment -

        It seems that changing AbstractSchemaManager.php to the following corrected the issue for me, however I am not sure of any repercussions that may arise as a result, being unfamiliar with the codebase.

        Doctrine/DBAL/Schema/AbstractSchemaManager.php line 228

        return new Table( $tableName, $columns, $indexes, $foreignKeys, false, array());

        Doctrine/DBAL/Schema/AbstractSchemaManager.php line 228

        return new Table( $this->_conn->getDatabase() . "." . $tableName, $columns, $indexes, $foreignKeys, false, array());

        Show
        Hugh Lomas added a comment - It seems that changing AbstractSchemaManager.php to the following corrected the issue for me, however I am not sure of any repercussions that may arise as a result, being unfamiliar with the codebase. Doctrine/DBAL/Schema/AbstractSchemaManager.php line 228 return new Table( $tableName, $columns, $indexes, $foreignKeys, false, array()); Doctrine/DBAL/Schema/AbstractSchemaManager.php line 228 return new Table( $this->_conn->getDatabase() . "." . $tableName, $columns, $indexes, $foreignKeys, false, array());
        Hide
        Benjamin Eberlei added a comment -

        Multi databases are not supported by schema manager and schema tool yet.

        Show
        Benjamin Eberlei added a comment - Multi databases are not supported by schema manager and schema tool yet.
        Benjamin Eberlei made changes -
        Issue Type Bug [ 1 ] Improvement [ 4 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 12614 ] jira-feedback [ 13922 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 13922 ] jira-feedback2 [ 15786 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 15786 ] jira-feedback3 [ 18043 ]

        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=DDC-1137, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Hugh Lomas
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: