From c5dde68976b1b5d777e1ec15bf32f9ae407a1f3f Mon Sep 17 00:00:00 2001 From: Fuwasegu <52437973+lunain84@users.noreply.github.com> Date: Mon, 7 Nov 2022 19:47:35 +0900 Subject: [PATCH 1/7] add tstzrange function (#74) * add tstzrange type * add tstzrange * add test * fix typo --- src/PostgresConnection.php | 2 + src/Schema/Blueprint.php | 9 ++++ src/Schema/Grammars/PostgresGrammar.php | 6 +++ src/Schema/Types/TsTzRangeType.php | 23 +++++++++ tests/Unit/Schema/Blueprint/PartitionTest.php | 9 ++++ tests/Unit/Schema/Types/TsTzRangeTypeTest.php | 49 +++++++++++++++++++ 6 files changed, 98 insertions(+) create mode 100644 src/Schema/Types/TsTzRangeType.php create mode 100644 tests/Unit/Schema/Types/TsTzRangeTypeTest.php diff --git a/src/PostgresConnection.php b/src/PostgresConnection.php index 3adbb02..218f038 100644 --- a/src/PostgresConnection.php +++ b/src/PostgresConnection.php @@ -18,6 +18,7 @@ use Umbrellio\Postgres\Schema\Subscribers\SchemaAlterTableChangeColumnSubscriber; use Umbrellio\Postgres\Schema\Types\NumericType; use Umbrellio\Postgres\Schema\Types\TsRangeType; +use Umbrellio\Postgres\Schema\Types\TsTzRangeType; class PostgresConnection extends BasePostgresConnection { @@ -29,6 +30,7 @@ class PostgresConnection extends BasePostgresConnection private $initialTypes = [ TsRangeType::TYPE_NAME => TsRangeType::class, + TsTzRangeType::TYPE_NAME => TsTzRangeType::class, NumericType::TYPE_NAME => NumericType::class, ]; diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index 2d473ec..37d4a38 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -19,6 +19,7 @@ use Umbrellio\Postgres\Schema\Definitions\ViewDefinition; use Umbrellio\Postgres\Schema\Types\DateRangeType; use Umbrellio\Postgres\Schema\Types\TsRangeType; +use Umbrellio\Postgres\Schema\Types\TsTzRangeType; class Blueprint extends BaseBlueprint { @@ -148,6 +149,14 @@ public function tsrange(string $column): Fluent return $this->addColumn(TsRangeType::TYPE_NAME, $column); } + /** + * @return Fluent|ColumnDefinition + */ + public function tstzrange(string $column): Fluent + { + return $this->addColumn(TsTzRangeType::TYPE_NAME, $column); + } + /** * @return Fluent|ColumnDefinition */ diff --git a/src/Schema/Grammars/PostgresGrammar.php b/src/Schema/Grammars/PostgresGrammar.php index f44e858..5bd1c54 100644 --- a/src/Schema/Grammars/PostgresGrammar.php +++ b/src/Schema/Grammars/PostgresGrammar.php @@ -19,6 +19,7 @@ use Umbrellio\Postgres\Schema\Types\DateRangeType; use Umbrellio\Postgres\Schema\Types\NumericType; use Umbrellio\Postgres\Schema\Types\TsRangeType; +use Umbrellio\Postgres\Schema\Types\TsTzRangeType; class PostgresGrammar extends BasePostgresGrammar { @@ -137,6 +138,11 @@ protected function typeTsrange(/** @scrutinizer ignore-unused */ Fluent $column) return TsRangeType::TYPE_NAME; } + protected function typeTstzrange(/** @scrutinizer ignore-unused */ Fluent $column): string + { + return TsTzRangeType::TYPE_NAME; + } + protected function typeDaterange(/** @scrutinizer ignore-unused */ Fluent $column): string { return DateRangeType::TYPE_NAME; diff --git a/src/Schema/Types/TsTzRangeType.php b/src/Schema/Types/TsTzRangeType.php new file mode 100644 index 0000000..6eda391 --- /dev/null +++ b/src/Schema/Types/TsTzRangeType.php @@ -0,0 +1,23 @@ +assertSameSql('alter table "test_table" add column "foo" tsrange not null'); } + /** + * @test + */ + public function addingTstzrangeColumn() + { + $this->blueprint->tstzrange('foo'); + $this->assertSameSql('alter table "test_table" add column "foo" tstzrange not null'); + } + /** * @test */ diff --git a/tests/Unit/Schema/Types/TsTzRangeTypeTest.php b/tests/Unit/Schema/Types/TsTzRangeTypeTest.php new file mode 100644 index 0000000..680c1b6 --- /dev/null +++ b/tests/Unit/Schema/Types/TsTzRangeTypeTest.php @@ -0,0 +1,49 @@ +type = $this + ->getMockBuilder(TsTzRangeType::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $this->abstractPlatform = $this->getMockForAbstractClass(AbstractPlatform::class); + } + + /** + * @test + */ + public function getSQLDeclaration(): void + { + $this->assertSame(TsTzRangeType::TYPE_NAME, $this->type->getSQLDeclaration([], $this->abstractPlatform)); + } + + /** + * @test + */ + public function getTypeName(): void + { + $this->assertSame(TsTzRangeType::TYPE_NAME, $this->type->getName()); + } +} From d590d994e825bacde0dc907eba311ff782f9819a Mon Sep 17 00:00:00 2001 From: Fuwasegu <52437973+lunain84@users.noreply.github.com> Date: Sun, 20 Nov 2022 01:39:21 +0900 Subject: [PATCH 2/7] add tstzrange method to phpdoc in .meta (#75) --- src/.meta.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/.meta.php b/src/.meta.php index 0a45d14..b02f6e7 100644 --- a/src/.meta.php +++ b/src/.meta.php @@ -34,6 +34,7 @@ class Schema { * @method Fluent dropView(string $view) * @method ColumnDefinition numeric(string $column, ?int $precision = null, ?int $scale = null) * @method ColumnDefinition tsrange(string $column) + * @method ColumnDefinition tstzrange(string $column) * @method ColumnDefinition daterange(string $column) * @method ExcludeDefinition exclude($columns, ?string $index = null) * @method CheckDefinition check($columns, ?string $index = null) From d96bf4bfb982ec7b237b6abd4300cc9bdee68553 Mon Sep 17 00:00:00 2001 From: Naoki Ikeguchi Date: Wed, 15 Mar 2023 20:00:20 +0900 Subject: [PATCH 3/7] feat: Add Laravel 10 Support (#77) * build(deps): Add Laravel 10 support * ci: Run on PHP 8.1 * build(deps): Require PHPUnit 9.6 * fix: Use getValues explicitly --- .github/workflows/ci.yml | 24 +++++++++++++++++++ composer.json | 7 +++--- ...SchemaAlterTableChangeColumnSubscriber.php | 6 +++-- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a69938e..65c6d85 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -127,6 +127,30 @@ jobs: coverage: false experimental: false exclude_group: WithoutSchema,forPHP7 + - operating_system: 'ubuntu-latest' + php_versions: '8.1' + postgres: '10' + experimental: false + coverage: false + exclude_group: WithoutSchema,forPHP7 + - operating_system: 'ubuntu-latest' + php_versions: '8.1' + postgres: '11' + experimental: false + coverage: false + exclude_group: WithoutSchema,forPHP7 + - operating_system: 'ubuntu-latest' + php_versions: '8.1' + postgres: '12' + experimental: false + coverage: true + exclude_group: WithoutSchema,forPHP7 + - operating_system: 'ubuntu-latest' + php_versions: '8.1' + postgres: '13' + coverage: false + experimental: false + exclude_group: WithoutSchema,forPHP7 runs-on: '${{ matrix.operating_system }}' services: postgres: diff --git a/composer.json b/composer.json index ccf9f79..f293881 100644 --- a/composer.json +++ b/composer.json @@ -36,13 +36,14 @@ "ext-pdo": "*", "php": "^7.2|^7.3|^7.4|^8.0", "doctrine/dbal": "^2.9|^3.0", - "laravel/framework": "^5.8|^6.0|^7.0|^8.0|^9.0" + "laravel/framework": "^5.8|^6.0|^7.0|^8.0|^9.0|^10.0" }, "require-dev": { "umbrellio/code-style-php": "^1.0", - "orchestra/testbench": "^3.5|^6.0|^4.0|^7.0", + "orchestra/testbench": "^3.5|^6.0|^4.0|^7.0|^8.0", "php-coveralls/php-coveralls": "^2.1", - "codeception/codeception": "^3.0|^4.0|^5.0.0-RC7" + "codeception/codeception": "^3.0|^4.0|^5.0", + "phpunit/phpunit": "^9.6" }, "scripts": { "lint": [ diff --git a/src/Schema/Subscribers/SchemaAlterTableChangeColumnSubscriber.php b/src/Schema/Subscribers/SchemaAlterTableChangeColumnSubscriber.php index 36c2139..9409809 100644 --- a/src/Schema/Subscribers/SchemaAlterTableChangeColumnSubscriber.php +++ b/src/Schema/Subscribers/SchemaAlterTableChangeColumnSubscriber.php @@ -15,6 +15,7 @@ use Doctrine\DBAL\Types\IntegerType; use Illuminate\Database\Query\Expression; use Illuminate\Support\Collection; +use Umbrellio\Postgres\Schema\Grammars\PostgresGrammar; final class SchemaAlterTableChangeColumnSubscriber implements EventSubscriber { @@ -197,8 +198,9 @@ public function compileAlterColumnType( public function getDefaultValueDeclarationSQL(AbstractPlatform $platform, Column $column): string { - if ($column->getDefault() instanceof Expression) { - return ' DEFAULT ' . $column->getDefault(); + $defaultValue = $column->getDefault(); + if ($defaultValue instanceof Expression) { + return ' DEFAULT ' . $defaultValue->getValue(new PostgresGrammar()); } return $platform->getDefaultValueDeclarationSQL($column->toArray()); From 67247474c530b17dd0e0f638ad82ca86c3aadaef Mon Sep 17 00:00:00 2001 From: Flemming Andersen Date: Wed, 10 May 2023 10:55:48 +0200 Subject: [PATCH 4/7] Fix deprecated string interpolation (#79) --- src/Schema/Grammars/PostgresGrammar.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Schema/Grammars/PostgresGrammar.php b/src/Schema/Grammars/PostgresGrammar.php index 5bd1c54..9bacf67 100644 --- a/src/Schema/Grammars/PostgresGrammar.php +++ b/src/Schema/Grammars/PostgresGrammar.php @@ -123,11 +123,11 @@ protected function typeNumeric(Fluent $column): string $scale = $column->get('scale'); if ($precision && $scale) { - return "${type}({$precision}, {$scale})"; + return "{$type}({$precision}, {$scale})"; } if ($precision) { - return "${type}({$precision})"; + return "{$type}({$precision})"; } return $type; From c65b1f01ef5b628b4267240c907dc3ad09f3c43b Mon Sep 17 00:00:00 2001 From: mpyw Date: Thu, 21 Dec 2023 20:06:52 +0900 Subject: [PATCH 5/7] Fix compatibility with laravel/framework#49231 (#82) --- src/Schema/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Schema/Builder.php b/src/Schema/Builder.php index 78f0761..eaf9e4e 100644 --- a/src/Schema/Builder.php +++ b/src/Schema/Builder.php @@ -28,7 +28,7 @@ public function dropView(string $view): void $this->build($blueprint); } - public function hasView(string $view): bool + public function hasView($view): bool { return count($this->connection->selectFromWriteConnection($this->grammar->compileViewExists(), [ $this->connection->getConfig()['schema'], From 190ae7a6638803226d36563cbe3e10cac454a050 Mon Sep 17 00:00:00 2001 From: KentarouTakeda Date: Fri, 22 Dec 2023 16:21:13 +0900 Subject: [PATCH 6/7] Fix compatibility with laravel/framework#49264 (#83) --- src/Schema/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Schema/Builder.php b/src/Schema/Builder.php index eaf9e4e..fbc25c5 100644 --- a/src/Schema/Builder.php +++ b/src/Schema/Builder.php @@ -36,7 +36,7 @@ public function hasView($view): bool ])) > 0; } - public function getForeignKeys(string $tableName): array + public function getForeignKeys($tableName): array { return $this->connection->selectFromWriteConnection($this->grammar->compileForeignKeysListing($tableName)); } From fa81f2ae8665fa263750ad16f500f34a52f30e6c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Dec 2023 08:22:59 +0100 Subject: [PATCH 7/7] Update phpunit/phpunit requirement from ^9.6 to ^9.6 || ^10.0 (#78) --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f293881..e4ae0dd 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ "orchestra/testbench": "^3.5|^6.0|^4.0|^7.0|^8.0", "php-coveralls/php-coveralls": "^2.1", "codeception/codeception": "^3.0|^4.0|^5.0", - "phpunit/phpunit": "^9.6" + "phpunit/phpunit": "^9.6 || ^10.0" }, "scripts": { "lint": [