Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #360 from bartv2/fixOracleNOTNULL

Don't add 'NOT NULL' to the 'ALTER TABLE' when that hasn't changed
  • Loading branch information...
commit 7ffb2701931aeae3bb32fa2012b9a575f3a7929b 2 parents d3c2e5e + eee502c
@guilhermeblanco guilhermeblanco authored
View
8 lib/Doctrine/DBAL/Platforms/OraclePlatform.php
@@ -629,7 +629,13 @@ public function getAlterTableSQL(TableDiff $diff)
* Do not add query part if only comment has changed
*/
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) {
View
22 tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
@@ -308,4 +308,26 @@ protected function getQuotedColumnInForeignKeySQL()
'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));
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.