From 2e506e6b4de673c3440abd19fad1f23ed9d00892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Brzozowski?= Date: Mon, 8 Apr 2019 18:24:43 +0200 Subject: [PATCH 1/2] Allow all values as default --- src/Generator.php | 2 +- tests/cases/GeneratorAddonsTestCase.php | 7 +++++++ .../migrations/m180324_153800_create_table_test_addons.php | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Generator.php b/src/Generator.php index f8110fc..2cbbc6d 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -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, diff --git a/tests/cases/GeneratorAddonsTestCase.php b/tests/cases/GeneratorAddonsTestCase.php index ecbdef8..d3543b9 100644 --- a/tests/cases/GeneratorAddonsTestCase.php +++ b/tests/cases/GeneratorAddonsTestCase.php @@ -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); + } } diff --git a/tests/migrations/m180324_153800_create_table_test_addons.php b/tests/migrations/m180324_153800_create_table_test_addons.php index 798f25e..3fd2c19 100644 --- a/tests/migrations/m180324_153800_create_table_test_addons.php +++ b/tests/migrations/m180324_153800_create_table_test_addons.php @@ -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'); From 2879580a56926d6e42ca72c4a47fcb30df858cd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Brzozowski?= Date: Mon, 8 Apr 2019 20:06:26 +0200 Subject: [PATCH 2/2] Empty strings as default for Updater --- src/table/TableChange.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/table/TableChange.php b/src/table/TableChange.php index 3b40b25..b9c06b9 100644 --- a/src/table/TableChange.php +++ b/src/table/TableChange.php @@ -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, @@ -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,