-
-
Notifications
You must be signed in to change notification settings - Fork 31
Feature/column position #226
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
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9fc53c0
Define new interface methods isFirst, getAfter and explicitly define …
puzzledpolymath 4482943
Add AbstractColumn stubs for methods first, isFirst, after, getAfter
puzzledpolymath 46f48f3
Implement MySQLColumn methods first, isFirst, after, getAfter. The on…
puzzledpolymath cc7498d
Implement column positioning within Handler, allowing added columns t…
puzzledpolymath fee8ed7
When adding a column after another, ensure the column already exists …
puzzledpolymath a727677
Add base test class for testing column positioning
puzzledpolymath e8774ad
Add MySQL test class for testing column positioning
puzzledpolymath 9e1d1e3
Readded getComment annotation and removed isFirst and getAfter method…
puzzledpolymath 336d23e
Removed first, isFirst, after, and getAfter methods. Which are now on…
puzzledpolymath 7fe7a1d
Removed white space, as no changes are needed for this file
puzzledpolymath 724ff17
Merge branch '2.x' into feature/column-position
puzzledpolymath 430d792
refactor: simplify column creation logic
roxblnfk 0d6f4b0
test(PositionColumn): add `DontGenerateAttribute` annotation
roxblnfk 9e0ac5f
Removed methods isFirst and getAfter from MySQLColumn class, not need…
puzzledpolymath a3af650
feat(MySQLColumn): convert `after` method into annotation declaration
roxblnfk 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
110 changes: 110 additions & 0 deletions
110
tests/Database/Functional/Driver/Common/Schema/PositionColumnTest.php
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,110 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Cycle\Database\Tests\Functional\Driver\Common\Schema; | ||
|
|
||
| use Cycle\Database\Driver\Handler; | ||
| use Cycle\Database\Exception\DBALException; | ||
| use Cycle\Database\Schema\AbstractColumn; | ||
| use Cycle\Database\Schema\AbstractTable; | ||
| use Cycle\Database\Tests\Functional\Driver\Common\BaseTest; | ||
| use Cycle\Database\Tests\Utils\DontGenerateAttribute; | ||
|
|
||
| #[DontGenerateAttribute] | ||
| abstract class PositionColumnTest extends BaseTest | ||
| { | ||
| public function testPositionFirst(): void | ||
| { | ||
| $schema = $this->sampleSchema('table'); | ||
|
|
||
| $this->assertTrue($schema->exists()); | ||
| $this->assertSameAsInDB($schema); | ||
|
|
||
| $schema->string('identifier')->nullable(false)->first(); | ||
| $schema->save(); | ||
|
|
||
| $this->assertSameAsInDB($schema); | ||
|
|
||
| $updatedSchema = $this->fetchSchema($schema); | ||
| $updatedColumnNames = \array_map(static fn(AbstractColumn $column) => $column->getName(), $updatedSchema->getColumns()); | ||
|
|
||
| $expectedColumnNames = [ | ||
| 'identifier' => 'identifier', | ||
| 'id' => 'id', | ||
| 'first_name' => 'first_name', | ||
| 'last_name' => 'last_name', | ||
| 'email' => 'email', | ||
| 'status' => 'status', | ||
| 'balance' => 'balance', | ||
| 'created_at' => 'created_at', | ||
| 'updated_at' => 'updated_at', | ||
| ]; | ||
|
|
||
| $this->assertSame($expectedColumnNames, $updatedColumnNames); | ||
| } | ||
|
|
||
| public function testPositionAfter(): void | ||
| { | ||
| $schema = $this->sampleSchema('table'); | ||
|
|
||
| $this->assertTrue($schema->exists()); | ||
| $this->assertSameAsInDB($schema); | ||
|
|
||
| $schema->string('identifier')->nullable(false)->after('email'); | ||
| $schema->save(); | ||
|
|
||
| $this->assertSameAsInDB($schema); | ||
|
|
||
| $updatedSchema = $this->fetchSchema($schema); | ||
| $updatedColumnNames = \array_map(static fn(AbstractColumn $column) => $column->getName(), $updatedSchema->getColumns()); | ||
|
|
||
| $expectedColumnNames = [ | ||
| 'id' => 'id', | ||
| 'first_name' => 'first_name', | ||
| 'last_name' => 'last_name', | ||
| 'email' => 'email', | ||
| 'identifier' => 'identifier', | ||
| 'status' => 'status', | ||
| 'balance' => 'balance', | ||
| 'created_at' => 'created_at', | ||
| 'updated_at' => 'updated_at', | ||
| ]; | ||
|
|
||
| $this->assertSame($expectedColumnNames, $updatedColumnNames); | ||
| } | ||
|
|
||
| public function testPositionAfterThrowsException(): void | ||
| { | ||
| $schema = $this->sampleSchema('table'); | ||
|
|
||
| $this->assertTrue($schema->exists()); | ||
| $this->assertSameAsInDB($schema); | ||
|
|
||
| $this->expectException(DBALException::class); | ||
| $this->expectExceptionMessage("Unknown column 'nonexistent'"); | ||
|
|
||
| $schema->string('identifier')->nullable(false)->after('nonexistent'); | ||
| $schema->save(); | ||
| } | ||
|
|
||
| private function sampleSchema(string $table): AbstractTable | ||
| { | ||
| $schema = $this->schema($table); | ||
|
|
||
| if (! $schema->exists()) { | ||
| $schema->primary('id'); | ||
| $schema->string('first_name')->nullable(false); | ||
| $schema->string('last_name')->nullable(false); | ||
| $schema->string('email', 64)->nullable(false); | ||
| $schema->enum('status', ['active', 'disabled'])->defaultValue('active'); | ||
| $schema->double('balance')->defaultValue(0); | ||
| $schema->datetime('created_at')->defaultValue(AbstractColumn::DATETIME_NOW); | ||
| $schema->datetime('updated_at')->nullable(true); | ||
|
|
||
| $schema->save(Handler::DO_ALL); | ||
| } | ||
|
|
||
| return $schema; | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
tests/Database/Functional/Driver/MySQL/Schema/PositionColumnTest.php
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,16 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Cycle\Database\Tests\Functional\Driver\MySQL\Schema; | ||
|
|
||
| use Cycle\Database\Tests\Functional\Driver\Common\Schema\PositionColumnTest as BaseTest; | ||
|
|
||
| /** | ||
| * @group driver | ||
| * @group driver-mysql | ||
| */ | ||
| class PositionColumnTest extends BaseTest | ||
| { | ||
| public const DRIVER = 'mysql'; | ||
| } |
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.