Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-67

OCI8: schema-tool:update is modifying not null boolean - NUMBER(1) columns to not null

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0-RC1-RC3
    • Fix Version/s: 2.0-RC4
    • Component/s: Schema Managers
    • Labels:
      None
    • Environment:
      Oracle - Oci8

      Description

      When I have a boolean column(s) in my entities and I want to update schema with schema tool, I get an exception:

      My entity:

      /** @Entity @Table(name='st_node') */
      class Node
      {
          /** @Id @Column(type="integer") @GeneratedValue */
          protected $id;
          
          /** @Column(type="string", length="255") */
          protected $title;
          
          /** @Column(type="boolean", nullable=false) */
          protected $is_published;
          
          /** @Column(type="boolean") */
          protected $is_sticky;
          
          /** @Column(type="integer", length=4) */
          protected $hits;
          
          /** @Column(type="decimal", precision=4, scale=2) */
          protected $score;
      }
      
      ./doctrine orm:schema-tool:update --force
      Entities\Address
      Entities\Node
      Entities\Article
      Entities\User
      Entities\Page
      Updating database schema...
      
        [Doctrine\DBAL\Driver\OCI8\OCI8Exception]                         
        ORA-01442: column to be modified to NOT NULL is already NOT NULL  
                  
      

      The same with --dump-sql option:

      ./doctrine orm:schema-tool:update --dump-sql
      Entities\Address
      Entities\Node
      Entities\Article
      Entities\User
      Entities\Page
      ALTER TABLE ST_NODE MODIFY (is_published  NUMBER(1) NOT NULL, is_sticky  NUMBER(1) NOT NULL)
      

      The columns are already not nulls, but schema-tool can't recognize that.

      This is the DQL of the table:

      CREATE TABLE "DOCTRINE"."ST_NODE"
        (
          "ID"           NUMBER(10,0) NOT NULL ENABLE,
          "TITLE"        VARCHAR2(255 BYTE) NOT NULL ENABLE,
          "DISCR"        VARCHAR2(255 BYTE) NOT NULL ENABLE,
          "IS_PUBLISHED" NUMBER(1,0) NOT NULL ENABLE,
          "HITS"         NUMBER(10,0) NOT NULL ENABLE,
          "SCORE"        NUMBER(4,2) NOT NULL ENABLE,
          "IS_STICKY"    NUMBER(1,0) NOT NULL ENABLE,
          PRIMARY KEY ("ID")
      );
      

        Activity

        Show
        Miloslav "adrive" Kmet added a comment - Fixed in https://github.com/milokmet/dbal/commits/DBAL-67
        Hide
        Benjamin Eberlei added a comment -

        Btw, with regard to the comment on the Fix on your repository.

        What has the commit to do with the NULL / NOT NULL issue? it seems the changes are entirely unrelated to this?

        Show
        Benjamin Eberlei added a comment - Btw, with regard to the comment on the Fix on your repository. What has the commit to do with the NULL / NOT NULL issue? it seems the changes are entirely unrelated to this?
        Hide
        Miloslav "adrive" Kmet added a comment -

        Hi Benjamin, No the changes are not unrelated to this, but I discover, what the problem was.

        The problem was, thet the changed function didn't map correctly the database column types to the doctrine's types.

        Therefor, when I have is_published column of doctrine's boolean type, it is mapped to oracle's NUMBER(1), but when I want to update the schema, doctrine schema managers thinks, that existing column in the database is integer with precision 1, and tries to modify the column to boolean -> number(1), but the column already is number(1) and oracle complains.

        The same is also with bigint and smallint.

        Show
        Miloslav "adrive" Kmet added a comment - Hi Benjamin, No the changes are not unrelated to this, but I discover, what the problem was. The problem was, thet the changed function didn't map correctly the database column types to the doctrine's types. Therefor, when I have is_published column of doctrine's boolean type, it is mapped to oracle's NUMBER(1), but when I want to update the schema, doctrine schema managers thinks, that existing column in the database is integer with precision 1, and tries to modify the column to boolean -> number(1), but the column already is number(1) and oracle complains. The same is also with bigint and smallint.
        Hide
        Benjamin Eberlei added a comment -

        Fixed

        Show
        Benjamin Eberlei added a comment - Fixed

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Miloslav "adrive" Kmet
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: