Skip to content

Commit

Permalink
Merge pull request #55 from phalcon/feature/#7-enum
Browse files Browse the repository at this point in the history
#7 - Add support of ENUM column type
  • Loading branch information
Jeckerson authored Feb 10, 2020
2 parents 6843613 + bbad3e3 commit b16acc0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/validations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion src/Mvc/Model/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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";
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Integration/MySQL/ColumnTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', ''],
]
];
}
Expand Down
3 changes: 2 additions & 1 deletion tests/var/issues/29/0.1.0/task_jobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b16acc0

Please sign in to comment.