Skip to content

Commit

Permalink
Merge branch 'default-empty-str'
Browse files Browse the repository at this point in the history
  • Loading branch information
Paweł Brzozowski committed Apr 8, 2019
2 parents 5829543 + 2879580 commit bc02e3f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ protected function getTableColumns(array $indexes = [], ?string $schema = null):
'isNotNull' => $column->allowNull ? null : true,
'isUnique' => $isUnique,
'check' => null,
'default' => $column->defaultValue ?: null,
'default' => $column->defaultValue,
'isPrimaryKey' => $column->isPrimaryKey,
'autoIncrement' => $column->autoIncrement,
'isUnsigned' => $column->unsigned,
Expand Down
4 changes: 2 additions & 2 deletions src/table/TableChange.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getValue()
'isUnique' => $schema['isUnique'] ?? null,
'isPrimaryKey' => $schema['isPrimaryKey'] ?? null,
'check' => $schema['check'] ?? null,
'default' => !empty($schema['default']) ? $schema['default'] : null,
'default' => $schema['default'],
'append' => $schema['append'] ?? null,
'isUnsigned' => $schema['isUnsigned'] ?? null,
'comment' => !empty($schema['comment']) ? $schema['comment'] : null,
Expand All @@ -82,7 +82,7 @@ public function getValue()
'isUnique' => $this->data[1]['isUnique'] ?? null,
'isPrimaryKey' => $this->data[1]['isPrimaryKey'] ?? null,
'check' => $this->data[1]['check'] ?? null,
'default' => !empty($this->data[1]['default']) ? $this->data[1]['default'] : null,
'default' => $this->data[1]['default'],
'append' => $this->data[1]['append'] ?? null,
'isUnsigned' => $this->data[1]['isUnsigned'] ?? null,
'comment' => !empty($this->data[1]['comment']) ? $this->data[1]['comment'] : null,
Expand Down
7 changes: 7 additions & 0 deletions tests/cases/GeneratorAddonsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ public function testColumnDefaultValue(): void
$this->assertArrayHasKey('col_default_value', $table->columns);
$this->assertEquals(1, $table->columns['col_default_value']->default);
}

public function testColumnDefaultEmptyValue(): void
{
$table = $this->getGenerator()->table;
$this->assertArrayHasKey('col_default_empty_value', $table->columns);
$this->assertSame('', $table->columns['col_default_empty_value']->default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function up(): void
'col_unsigned' => $this->integer()->unsigned(),
'col_not_null' => $this->integer()->notNull(),
'col_default_value' => $this->integer()->defaultValue(1),
'col_default_empty_value' => $this->string()->defaultValue(''),
];
if ($this->db->driverName !== 'sqlite') {
$structure['col_comment'] = $this->string()->comment('comment');
Expand Down

0 comments on commit bc02e3f

Please sign in to comment.