Convert boolean values properly for default value declarations

parent 3a77cd68
......@@ -1655,6 +1655,9 @@ abstract class AbstractPlatform
$default = " DEFAULT ".$field['default'];
} else if ((string)$field['type'] == 'DateTime' && $field['default'] == $this->getCurrentTimestampSQL()) {
$default = " DEFAULT ".$this->getCurrentTimestampSQL();
} else if ((string) $field['type'] == 'Boolean') {
$default = " DEFAULT '" . $this->convertBooleans($field['default']) . "'";
}
}
}
......
......@@ -203,18 +203,22 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
{
$expectedSql = $this->getGenerateAlterTableSql();
$columnDiff = new \Doctrine\DBAL\Schema\ColumnDiff(
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable');
$tableDiff->newName = 'userlist';
$tableDiff->addedColumns['quota'] = new \Doctrine\DBAL\Schema\Column('quota', \Doctrine\DBAL\Types\Type::getType('integer'), array('notnull' => false));
$tableDiff->removedColumns['foo'] = new \Doctrine\DBAL\Schema\Column('foo', \Doctrine\DBAL\Types\Type::getType('integer'));
$tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff(
'bar', new \Doctrine\DBAL\Schema\Column(
'baz', \Doctrine\DBAL\Types\Type::getType('string'), array('default' => 'def')
),
array('type', 'notnull', 'default')
);
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable');
$tableDiff->newName = 'userlist';
$tableDiff->addedColumns['quota'] = new \Doctrine\DBAL\Schema\Column('quota', \Doctrine\DBAL\Types\Type::getType('integer'), array('notnull' => false));
$tableDiff->removedColumns['foo'] = new \Doctrine\DBAL\Schema\Column('foo', \Doctrine\DBAL\Types\Type::getType('integer'));
$tableDiff->changedColumns['bar'] = $columnDiff;
$tableDiff->changedColumns['bloo'] = new \Doctrine\DBAL\Schema\ColumnDiff(
'bloo', new \Doctrine\DBAL\Schema\Column(
'bloo', \Doctrine\DBAL\Types\Type::getType('boolean'), array('default' => false)
),
array('type', 'notnull', 'default')
);
$sql = $this->_platform->getAlterTableSQL($tableDiff);
......
......@@ -40,7 +40,7 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
public function getGenerateAlterTableSql()
{
return array(
"ALTER TABLE mytable RENAME TO userlist, ADD quota INT DEFAULT NULL, DROP foo, CHANGE bar baz VARCHAR(255) DEFAULT 'def' NOT NULL"
"ALTER TABLE mytable RENAME TO userlist, ADD quota INT DEFAULT NULL, DROP foo, CHANGE bar baz VARCHAR(255) DEFAULT 'def' NOT NULL, CHANGE bloo bloo TINYINT(1) DEFAULT '0' NOT NULL"
);
}
......
......@@ -31,7 +31,7 @@ class OraclePlatformTest extends AbstractPlatformTestCase
{
return array(
'ALTER TABLE mytable ADD (quota NUMBER(10) DEFAULT NULL)',
"ALTER TABLE mytable MODIFY (baz VARCHAR2(255) DEFAULT 'def' NOT NULL)",
"ALTER TABLE mytable MODIFY (baz VARCHAR2(255) DEFAULT 'def' NOT NULL, bloo NUMBER(1) DEFAULT '0' NOT NULL)",
"ALTER TABLE mytable DROP (foo)",
"ALTER TABLE mytable RENAME TO userlist",
);
......
......@@ -35,6 +35,9 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
'ALTER TABLE mytable ALTER bar TYPE VARCHAR(255)',
"ALTER TABLE mytable ALTER bar SET DEFAULT 'def'",
'ALTER TABLE mytable ALTER bar SET NOT NULL',
'ALTER TABLE mytable ALTER bloo TYPE BOOLEAN',
"ALTER TABLE mytable ALTER bloo SET DEFAULT 'false'",
'ALTER TABLE mytable ALTER bloo SET NOT NULL',
'ALTER TABLE mytable RENAME TO userlist',
);
}
......
......@@ -32,6 +32,7 @@ class SQLServerPlatformTest extends AbstractPlatformTestCase
'ALTER TABLE mytable ADD quota INT DEFAULT NULL',
'ALTER TABLE mytable DROP COLUMN foo',
'ALTER TABLE mytable ALTER COLUMN baz NVARCHAR(255) DEFAULT \'def\' NOT NULL',
'ALTER TABLE mytable ALTER COLUMN bloo BIT DEFAULT \'0\' NOT NULL',
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment