[DBAL-511] Schema\ColumnDiff incorrect with default varchar value and postgresql Created: 01/May/13  Updated: 04/May/13  Resolved: 04/May/13

Status: Resolved
Project: Doctrine DBAL
Component/s: Schema Managers
Affects Version/s: None
Fix Version/s: 2.4, 2.3.4
Security Level: All

Type: Bug Priority: Major
Reporter: Richard Hinkamp Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None
Environment:

Ubuntu 12.04.2 LTS
PHP 5.3.10-1ubuntu3.6
PostgreSQL(libpq) Version => 9.1.8



 Description   

I have a Schema\Table with a column:

$usersTable->addColumn("lastip", "string", array("length" => 32, "default" => ""));

When I use Schema\Comparator on this table I get a ColumnDiff:

object(Doctrine\DBAL\Schema\ColumnDiff)[554]
  public 'oldColumnName' => string 'lastip' (length=6)
  public 'column' => 
    object(Doctrine\DBAL\Schema\Column)[481]
      protected '_type' => 
        object(Doctrine\DBAL\Types\StringType)[278]
      protected '_length' => int 32
      protected '_precision' => int 10
      protected '_scale' => int 0
      protected '_unsigned' => boolean false
      protected '_fixed' => boolean false
      protected '_notnull' => boolean true
      protected '_default' => string '' (length=0)
      protected '_autoincrement' => boolean false
      protected '_platformOptions' => 
        array
          empty
      protected '_columnDefinition' => null
      protected '_comment' => null
      protected '_customSchemaOptions' => 
        array
          empty
      protected '_name' => string 'lastip' (length=6)
      protected '_namespace' => null
      protected '_quoted' => boolean false
  public 'changedProperties' => 
    array
      0 => string 'default' (length=7)
  public 'fromColumn' => 
    object(Doctrine\DBAL\Schema\Column)[293]
      protected '_type' => 
        object(Doctrine\DBAL\Types\StringType)[278]
      protected '_length' => int 32
      protected '_precision' => int 10
      protected '_scale' => int 0
      protected '_unsigned' => boolean false
      protected '_fixed' => boolean false
      protected '_notnull' => boolean true
      protected '_default' => string '''::character varying' (length=21)
      protected '_autoincrement' => boolean false
      protected '_platformOptions' => 
        array
          empty
      protected '_columnDefinition' => null
      protected '_comment' => string '' (length=0)
      protected '_customSchemaOptions' => 
        array
          empty
      protected '_name' => string 'lastip' (length=6)
      protected '_namespace' => null
      protected '_quoted' => boolean false

With "default" postgresql adds "::character varying" when it's a varchar.

This gives a alter sql query:

ALTER TABLE bolt_users ALTER lastip SET  DEFAULT ''

After executing this, the next time it's the ColumnDiff again. Should the "::character varying" part be ignored by doctrine? Because then the schema will be valid.

Using Doctrine 2.4.0-BETA1 (38b1a340c5ec7c58be1883696c1f956bed5b7f0c)



 Comments   
Comment by Benjamin Eberlei [ 01/May/13 ]

Duplicate of DBAL-483

Comment by Richard Hinkamp [ 02/May/13 ]

Hmm that's not a duplicate. The default column handling works great in mysql, sqlite and with integer/date/etc fields in postgres, just not with varchar and postgres. I think doctrine should handle the "::character varying" part which postgres adds to the default value of a varchar field.

Comment by Benjamin Eberlei [ 04/May/13 ]

Yes you are right, fixed the underlying issue now.

Generated at Sat Jul 26 11:17:27 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.