-
-
Notifications
You must be signed in to change notification settings - Fork 13
Add ENUM column
#404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Add ENUM column
#404
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
db8cba8
start
vjik bca0395
improve
vjik 7bb2ec9
Apply PHP CS Fixer and Rector changes (CI)
vjik e10df71
test
vjik f75475d
fix
vjik 6a5bf04
fix
vjik 9dd9b6e
Apply PHP CS Fixer and Rector changes (CI)
vjik 938501d
improve
vjik bb2d12e
Merge branch 'master' into enum-col
vjik 6a60f4a
improve
vjik d39eb95
improve
vjik 3925bcf
improve regexp
vjik 3e6755f
more tests
vjik 41a0f8a
improve
vjik c11c61a
changelog
vjik 21a1b98
fix
vjik 2eccd9f
improve
vjik 36d47a4
fix
vjik 0a6a1b3
more tests
vjik 16bab24
Update src/Schema.php
vjik 11bafb0
Update src/Schema.php
vjik 9ffc8cc
fix
vjik 339c90d
fix
vjik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yiisoft\Db\Sqlite\Tests\Column; | ||
|
|
||
| use PHPUnit\Framework\Attributes\TestWith; | ||
| use Yiisoft\Db\Schema\Column\EnumColumn; | ||
| use Yiisoft\Db\Sqlite\Tests\Support\IntegrationTestTrait; | ||
| use Yiisoft\Db\Tests\Common\CommonEnumColumnTest; | ||
|
|
||
| final class EnumColumnTest extends CommonEnumColumnTest | ||
| { | ||
| use IntegrationTestTrait; | ||
|
|
||
| #[TestWith(['INTEGER CHECK (status IN (1, 2, 3))'])] | ||
| #[TestWith(["TEXT CHECK (status != 'abc')"])] | ||
| #[TestWith(["TEXT CHECK (status NOT IN ('a', 'b', 'c'))"])] | ||
| #[TestWith(["TEXT CHECK ('status' not IN ('a', 'b', 'c'))"])] | ||
| #[TestWith(["TEXT CHECK (\"Status\" IN ('a', 'b', 'c'))"])] | ||
| #[TestWith(["TEXT CHECK ('Status' IN ('a', 'b', 'c'))"])] | ||
| #[TestWith(["TEXT CHECK ([Status] IN ('a', 'b', 'c'))"])] | ||
| public function testNonEnumCheck(string $columnDefinition): void | ||
| { | ||
| $this->dropTable('test_enum_table'); | ||
| $this->executeStatements( | ||
| <<<SQL | ||
| CREATE TABLE test_enum_table ( | ||
| id INTEGER, | ||
| status $columnDefinition | ||
| ) | ||
| SQL, | ||
| ); | ||
|
|
||
| $db = $this->getSharedConnection(); | ||
| $column = $db->getTableSchema('test_enum_table')->getColumn('status'); | ||
|
|
||
| $this->assertNotInstanceOf(EnumColumn::class, $column); | ||
|
|
||
| $this->dropTable('test_enum_table'); | ||
| } | ||
|
|
||
| #[TestWith([ | ||
| 'knot', | ||
| "TEXT CHECK (knot IN ('a', 'b'))", | ||
| ['a', 'b'], | ||
| ])] | ||
| #[TestWith([ | ||
| 'status', | ||
| "TEXT CHECK (status in ('a', 'b'))", | ||
| ['a', 'b'], | ||
| ])] | ||
| #[TestWith([ | ||
| 'letter', | ||
| "TEXT CHECK (letter IN ('a', 'b'))", | ||
| ['a', 'b'], | ||
| ])] | ||
| #[TestWith([ | ||
| 'letter', | ||
| "TEXT CHECK (LETTER IN ('a', 'b'))", | ||
| ['a', 'b'], | ||
| ])] | ||
| #[TestWith([ | ||
| 'letter', | ||
| "TEXT CHECK (`letter` IN ('a', 'b'))", | ||
| ['a', 'b'], | ||
| ])] | ||
| #[TestWith([ | ||
| 'letter', | ||
| "TEXT CHECK ([letter] IN ('a', 'b'))", | ||
| ['a', 'b'], | ||
| ])] | ||
| #[TestWith([ | ||
| 'letter', | ||
| "TEXT CHECK (\"letter\" IN ('a', 'b'))", | ||
| ['a', 'b'], | ||
| ])] | ||
| #[TestWith([ | ||
| 'status', | ||
| "TEXT CHECK (status IN\n(\n'a',\n'b'\n))", | ||
| ['a', 'b'], | ||
| ])] | ||
| public function testEnumCheck(string $columnName, string $columnDefinition, array $expectedValues): void | ||
| { | ||
| $this->dropTable('test_enum_table'); | ||
|
|
||
| $quotedColumnName = $this->getSharedConnection()->getQuoter()->quoteColumnName($columnName); | ||
| $this->executeStatements( | ||
| <<<SQL | ||
| CREATE TABLE test_enum_table ( | ||
| id INTEGER, | ||
| $quotedColumnName $columnDefinition | ||
| ) | ||
| SQL, | ||
| ); | ||
|
|
||
| $db = $this->getSharedConnection(); | ||
| $column = $db->getTableSchema('test_enum_table')->getColumn($columnName); | ||
|
|
||
| $this->assertInstanceOf(EnumColumn::class, $column, $column::class); | ||
| $this->assertEqualsCanonicalizing($expectedValues, $column->getValues()); | ||
|
|
||
| $this->dropTable('test_enum_table'); | ||
| } | ||
vjik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| protected function createDatabaseObjectsStatements(): array | ||
| { | ||
| return [ | ||
| <<<SQL | ||
| CREATE TABLE tbl_enum ( | ||
| id INTEGER, | ||
| status TEXT CHECK(status IN ('active', 'unactive', 'pending')) | ||
vjik marked this conversation as resolved.
Show resolved
Hide resolved
vjik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| SQL, | ||
| ]; | ||
| } | ||
|
|
||
| protected function dropDatabaseObjectsStatements(): array | ||
| { | ||
| return [ | ||
| 'DROP TABLE IF EXISTS tbl_enum', | ||
| ]; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.