Skip to content

Commit 18bf93e

Browse files
committed
Merge branch '0.x' into 0.next
2 parents 9ba5deb + 9a6ce1e commit 18bf93e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Phinx/Db/Adapter/SqlServerAdapter.php

+4
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,13 @@ public function getColumns(string $tableName): array
494494
*/
495495
protected function parseDefault(?string $default)
496496
{
497+
// if a column is non-nullable and has no default, the value of column_default is null,
498+
// otherwise it should be a string value that we parse below, including "(NULL)" which
499+
// also stands for a null default
497500
if ($default === null) {
498501
return null;
499502
}
503+
500504
$result = preg_replace(["/\('(.*)'\)/", "/\(\((.*)\)\)/", "/\((.*)\)/"], '$1', $default);
501505

502506
if (strtoupper($result) === 'NULL') {

tests/Phinx/Db/Adapter/SqlServerAdapterTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,21 @@ public function testAddColumnWithDefaultNull()
426426
}
427427
}
428428

429+
public function testAddColumnWithNotNullableNoDefault()
430+
{
431+
$table = new \Phinx\Db\Table('table1', [], $this->adapter);
432+
$table
433+
->addColumn('col', 'string', ['null' => false])
434+
->create();
435+
436+
$columns = $this->adapter->getColumns('table1');
437+
$this->assertCount(2, $columns);
438+
$this->assertArrayHasKey('id', $columns);
439+
$this->assertArrayHasKey('col', $columns);
440+
$this->assertFalse($columns['col']->isNull());
441+
$this->assertNull($columns['col']->getDefault());
442+
}
443+
429444
public function testAddColumnWithDefaultBool()
430445
{
431446
$table = new \Phinx\Db\Table('table1', [], $this->adapter);

0 commit comments

Comments
 (0)