|
12 | 12 | use Yiisoft\Db\Exception\InvalidConfigException; |
13 | 13 | use Yiisoft\Db\Exception\NotSupportedException; |
14 | 14 | use Yiisoft\Db\Expression\Expression; |
| 15 | +use Yiisoft\Db\Mssql\Column; |
15 | 16 | use Yiisoft\Db\Mssql\Connection; |
16 | 17 | use Yiisoft\Db\Mssql\Dsn; |
17 | 18 | use Yiisoft\Db\Mssql\Driver; |
@@ -353,4 +354,27 @@ public function testShowDatabases(): void |
353 | 354 | $this->assertSame('sqlsrv:Server=localhost,1433;', $db->getDriver()->getDsn()); |
354 | 355 | $this->assertSame(['yiitest'], $command->showDatabases()); |
355 | 356 | } |
| 357 | + |
| 358 | + /** @link https://github.com/yiisoft/db-migration/issues/11 */ |
| 359 | + public function testAlterColumnWithDefaultNull() |
| 360 | + { |
| 361 | + $db = $this->getConnection(); |
| 362 | + $command = $db->createCommand(); |
| 363 | + |
| 364 | + if ($db->getTableSchema('column_with_constraint', true) !== null) { |
| 365 | + $command->dropTable('column_with_constraint')->execute(); |
| 366 | + } |
| 367 | + |
| 368 | + $command->createTable('column_with_constraint', ['id' => 'pk'])->execute(); |
| 369 | + $command->addColumn('column_with_constraint', 'field', (new Column('integer'))->null()->asString())->execute(); |
| 370 | + $command->alterColumn('column_with_constraint', 'field', (new Column('string', 40))->notNull()->asString())->execute(); |
| 371 | + |
| 372 | + $fieldCol = $db->getTableSchema('column_with_constraint', true)->getColumn('field'); |
| 373 | + |
| 374 | + $this->assertFalse($fieldCol->isAllowNull()); |
| 375 | + $this->assertNull($fieldCol->getDefaultValue()); |
| 376 | + $this->assertSame('nvarchar(40)', $fieldCol->getDbType()); |
| 377 | + |
| 378 | + $command->dropTable('column_with_constraint'); |
| 379 | + } |
356 | 380 | } |
0 commit comments