diff --git a/.github/workflows/validations.yml b/.github/workflows/validations.yml index 7b425fc..3e43258 100644 --- a/.github/workflows/validations.yml +++ b/.github/workflows/validations.yml @@ -2,7 +2,7 @@ name: "Validations" on: [push, pull_request] jobs: validate-code-style: - name: PSR-2 Code style + name: PSR-12 Code style runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 @@ -24,7 +24,7 @@ jobs: - name: Install PHP_CodeSniffer composer package run: composer global require "squizlabs/php_codesniffer=*" - - name: Validate PSR-2 Code Style + - name: Validate PSR-12 Code Style run: ~/.composer/vendor/bin/phpcs validate-code-static: diff --git a/src/Mvc/Model/Migration.php b/src/Mvc/Model/Migration.php index 4e5b4de..70e6820 100644 --- a/src/Mvc/Model/Migration.php +++ b/src/Mvc/Model/Migration.php @@ -299,6 +299,9 @@ public static function generate( case Column::TYPE_JSONB: $fieldDefinition[] = "'type' => Column::TYPE_JSONB"; break; + case Column::TYPE_ENUM: + $fieldDefinition[] = "'type' => Column::TYPE_ENUM"; + break; default: throw new UnknownColumnTypeException($field); } @@ -356,7 +359,11 @@ public static function generate( // nothing } else { if ($field->getSize()) { - $fieldDefinition[] = "'size' => " . $field->getSize(); + if ($field->getType() === Column::TYPE_ENUM) { + $fieldDefinition[] = "'size' => \"" . $field->getSize() . "\""; + } else { + $fieldDefinition[] = "'size' => " . $field->getSize(); + } } elseif (!in_array($field->getType(), $noSizeTypes)) { $fieldDefinition[] = "'size' => 1"; } diff --git a/tests/Integration/MySQL/ColumnTypesTest.php b/tests/Integration/MySQL/ColumnTypesTest.php index 0232f0b..f5c2c52 100644 --- a/tests/Integration/MySQL/ColumnTypesTest.php +++ b/tests/Integration/MySQL/ColumnTypesTest.php @@ -74,6 +74,15 @@ public function columnsDataProvider(): array 'notNull' => true, ], ['{}', '{"type": "json"}', '{"random": 123, "is_true": false}'], + ], + [ + 'column_enum_not_null', + [ + 'type' => Column::TYPE_ENUM, + 'size' => "'Y','N','D', ''", + 'notNull' => true, + ], + ['Y', 'N', 'D', ''], ] ]; } diff --git a/tests/var/issues/29/0.1.0/task_jobs.php b/tests/var/issues/29/0.1.0/task_jobs.php index dd4b735..d469e53 100644 --- a/tests/var/issues/29/0.1.0/task_jobs.php +++ b/tests/var/issues/29/0.1.0/task_jobs.php @@ -27,7 +27,8 @@ public function morph() new Column('task_id', [ 'type' => Column::TYPE_INTEGER, 'size' => 20, - 'after' => 'id' + 'after' => 'id', + 'notNull' => false ]), new Column('run_at', [ 'type' => Column::TYPE_DATETIME,