From c0ee81929362dcbbe931366494caa50352a1d0df Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 7 Feb 2020 17:25:29 +0000 Subject: [PATCH 1/6] #7 - Add support of ENUM column type --- src/Mvc/Model/Migration.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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"; } From c5863cb432207a69abaf84f5cc5dd4b30894863a Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 7 Feb 2020 17:25:46 +0000 Subject: [PATCH 2/6] #7 - Add support of ENUM column type test --- tests/Integration/MySQL/ColumnTypesTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/Integration/MySQL/ColumnTypesTest.php b/tests/Integration/MySQL/ColumnTypesTest.php index 0232f0b..c701b39 100644 --- a/tests/Integration/MySQL/ColumnTypesTest.php +++ b/tests/Integration/MySQL/ColumnTypesTest.php @@ -15,6 +15,7 @@ use Exception; use Phalcon\Db\Column; +use Phalcon\Db\Dialect\Mysql; use Phalcon\Db\Enum; use Phalcon\Helper\Arr; use Phalcon\Migrations\Migrations; @@ -74,6 +75,15 @@ public function columnsDataProvider(): array 'notNull' => true, ], ['{}', '{"type": "json"}', '{"random": 123, "is_true": false}'], + ], + [ + 'column_enum_not_null', + [ + 'type' => Column::TYPE_INTEGER, + 'size' => "'Y','N','D', ''", + 'notNull' => true, + ], + ['Y', 'N', 'D', ''], ] ]; } From c561f2b2046f66b506301ee77a6d6d7747c798fe Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 10 Feb 2020 13:47:07 +0000 Subject: [PATCH 3/6] #7 - Change column type to ENUM --- tests/Integration/MySQL/ColumnTypesTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/MySQL/ColumnTypesTest.php b/tests/Integration/MySQL/ColumnTypesTest.php index c701b39..ca9b68f 100644 --- a/tests/Integration/MySQL/ColumnTypesTest.php +++ b/tests/Integration/MySQL/ColumnTypesTest.php @@ -79,7 +79,7 @@ public function columnsDataProvider(): array [ 'column_enum_not_null', [ - 'type' => Column::TYPE_INTEGER, + 'type' => Column::TYPE_ENUM, 'size' => "'Y','N','D', ''", 'notNull' => true, ], From e37d5b34cd15efc77aa21bd5335890db8bbf6b60 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 10 Feb 2020 14:03:22 +0000 Subject: [PATCH 4/6] #7 - Add 'notNull' => false to make foreign key identical to source --- tests/var/issues/29/0.1.0/task_jobs.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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, From 8657c771b233c0ae3e6ffba2429079dc843f8aee Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 10 Feb 2020 15:44:41 +0000 Subject: [PATCH 5/6] #7 - Clean imports --- tests/Integration/MySQL/ColumnTypesTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Integration/MySQL/ColumnTypesTest.php b/tests/Integration/MySQL/ColumnTypesTest.php index ca9b68f..f5c2c52 100644 --- a/tests/Integration/MySQL/ColumnTypesTest.php +++ b/tests/Integration/MySQL/ColumnTypesTest.php @@ -15,7 +15,6 @@ use Exception; use Phalcon\Db\Column; -use Phalcon\Db\Dialect\Mysql; use Phalcon\Db\Enum; use Phalcon\Helper\Arr; use Phalcon\Migrations\Migrations; From bbad3e32c8c38ce1769986ef1aacbb35bd86a72f Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 10 Feb 2020 15:45:25 +0000 Subject: [PATCH 6/6] #7 - Rename PSR-2 to PSR-12 --- .github/workflows/validations.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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: