Commit 7ffb2701 authored by Guilherme Blanco's avatar Guilherme Blanco

Merge pull request #360 from bartv2/fixOracleNOTNULL

Don't add 'NOT NULL' to the 'ALTER TABLE' when that hasn't changed
parents d3c2e5e5 eee502c9
...@@ -629,7 +629,13 @@ LEFT JOIN user_cons_columns r_cols ...@@ -629,7 +629,13 @@ LEFT JOIN user_cons_columns r_cols
* Do not add query part if only comment has changed * Do not add query part if only comment has changed
*/ */
if ( ! ($columnHasChangedComment && count($columnDiff->changedProperties) === 1)) { if ( ! ($columnHasChangedComment && count($columnDiff->changedProperties) === 1)) {
$fields[] = $column->getQuotedName($this). ' ' . $this->getColumnDeclarationSQL('', $column->toArray()); $columnInfo = $column->toArray();
if ( ! $columnDiff->hasChanged('notnull')) {
$columnInfo['notnull'] = false;
}
$fields[] = $column->getQuotedName($this) . ' ' . $this->getColumnDeclarationSQL('', $columnInfo);
} }
if ($columnHasChangedComment) { if ($columnHasChangedComment) {
......
...@@ -308,4 +308,26 @@ class OraclePlatformTest extends AbstractPlatformTestCase ...@@ -308,4 +308,26 @@ class OraclePlatformTest extends AbstractPlatformTestCase
'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar")', 'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar")',
); );
} }
public function testAlterTableNotNULL()
{
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable');
$tableDiff->changedColumns['foo'] = new \Doctrine\DBAL\Schema\ColumnDiff(
'foo', new \Doctrine\DBAL\Schema\Column(
'foo', \Doctrine\DBAL\Types\Type::getType('string'), array('default' => 'bla', 'notnull' => true)
),
array('type')
);
$tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff(
'bar', new \Doctrine\DBAL\Schema\Column(
'baz', \Doctrine\DBAL\Types\Type::getType('string'), array('default' => 'bla', 'notnull' => true)
),
array('type', 'notnull')
);
$expectedSql = array(
"ALTER TABLE mytable MODIFY (foo VARCHAR2(255) DEFAULT 'bla', baz VARCHAR2(255) DEFAULT 'bla' NOT NULL)",
);
$this->assertEquals($expectedSql, $this->_platform->getAlterTableSQL($tableDiff));
}
} }
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