Skip to content

Commit

Permalink
Merge branch '0.x' into 0.next
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterOdin committed Jul 15, 2022
2 parents 9ba5deb + 9a6ce1e commit 18bf93e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Phinx/Db/Adapter/SqlServerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,13 @@ public function getColumns(string $tableName): array
*/
protected function parseDefault(?string $default)
{
// if a column is non-nullable and has no default, the value of column_default is null,
// otherwise it should be a string value that we parse below, including "(NULL)" which
// also stands for a null default
if ($default === null) {
return null;
}

$result = preg_replace(["/\('(.*)'\)/", "/\(\((.*)\)\)/", "/\((.*)\)/"], '$1', $default);

if (strtoupper($result) === 'NULL') {
Expand Down
15 changes: 15 additions & 0 deletions tests/Phinx/Db/Adapter/SqlServerAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,21 @@ public function testAddColumnWithDefaultNull()
}
}

public function testAddColumnWithNotNullableNoDefault()
{
$table = new \Phinx\Db\Table('table1', [], $this->adapter);
$table
->addColumn('col', 'string', ['null' => false])
->create();

$columns = $this->adapter->getColumns('table1');
$this->assertCount(2, $columns);
$this->assertArrayHasKey('id', $columns);
$this->assertArrayHasKey('col', $columns);
$this->assertFalse($columns['col']->isNull());
$this->assertNull($columns['col']->getDefault());
}

public function testAddColumnWithDefaultBool()
{
$table = new \Phinx\Db\Table('table1', [], $this->adapter);
Expand Down

0 comments on commit 18bf93e

Please sign in to comment.