From 2d1f4da08412e1335d981cc7d58d9c9c6f398009 Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Fri, 15 Mar 2024 15:00:51 +0900 Subject: [PATCH 1/7] feat: laravel 11 support --- Dockerfile | 2 +- composer.json | 12 ++++++------ src/Query/ArrayValue.php | 30 ++++++++++++++++++++++++++++++ src/Query/Builder.php | 15 +++++++++++++++ src/Query/Grammar.php | 15 +++++++++++++++ src/Schema/Blueprint.php | 2 +- tests/ConnectionTest.php | 20 ++++++++++---------- tests/Query/BuilderTest.php | 10 +++++----- 8 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 src/Query/ArrayValue.php diff --git a/Dockerfile b/Dockerfile index 37c2809..2685637 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM php:8.1-cli-alpine +FROM php:8.2-cli-alpine COPY --from=composer:2 /usr/bin/composer /usr/bin/composer diff --git a/composer.json b/composer.json index 8ca7619..b9b1b4f 100644 --- a/composer.json +++ b/composer.json @@ -8,19 +8,19 @@ {"name": "Takayasu Oyama", "email": "t-oyama@colopl.co.jp"} ], "require": { - "php": "^8.1", + "php": "^8.2", "ext-grpc": "*", "ext-json": "*", - "laravel/framework": "^10.37.0", + "laravel/framework": "^10.37.0|^11", "google/cloud-spanner": "^1.58.4", "grpc/grpc": "^1.42", - "symfony/cache": "~6", + "symfony/cache": "~7", "symfony/deprecation-contracts": "~2", - "symfony/lock": "~6" + "symfony/lock": "~7" }, "require-dev": { - "orchestra/testbench": "~8", - "phpunit/phpunit": "~10.0", + "orchestra/testbench": "~9", + "phpunit/phpunit": "~11.0", "phpstan/phpstan": "^1" }, "autoload": { diff --git a/src/Query/ArrayValue.php b/src/Query/ArrayValue.php new file mode 100644 index 0000000..5484d4b --- /dev/null +++ b/src/Query/ArrayValue.php @@ -0,0 +1,30 @@ +prepareInsertForDml($values)); } + /** + * @inheritDoc + */ + public function update(array $values) + { + foreach ($values as $key => $value) { + if (is_array($value)) { + $values[$key] = new ArrayValue($value); + } + } + + return parent::update($values); + } + /** * @inheritDoc */ diff --git a/src/Query/Grammar.php b/src/Query/Grammar.php index bc2c9af..ce3f877 100644 --- a/src/Query/Grammar.php +++ b/src/Query/Grammar.php @@ -22,6 +22,7 @@ use Illuminate\Database\Query\Builder; use Illuminate\Contracts\Database\Query\Expression; use Illuminate\Database\Query\Grammars\Grammar as BaseGrammar; +use Illuminate\Support\Arr; use RuntimeException; class Grammar extends BaseGrammar @@ -45,6 +46,20 @@ protected function compileLock(Builder $query, $value) return ''; } + /** + * @inheritDoc + */ + public function prepareBindingsForUpdate(array $bindings, array $values) + { + $bindings = parent::prepareBindingsForUpdate($bindings, $values); + foreach ($bindings as $key => $value) { + if ($value instanceof ArrayValue) { + $bindings[$key] = $value->value; + } + } + return $bindings; + } + /** * @inheritDoc */ diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index 0d3c896..ced2ecb 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -127,7 +127,7 @@ public function uuid($column = 'uuid') * @param int|null $length * @return ColumnDefinition */ - public function binary($column, $length = null) + public function binary($column, $length = null, $fixed = false) { $length = $length ?: Builder::$defaultBinaryLength; diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 95f46e5..4e71ebb 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -350,10 +350,10 @@ public function testQueryExecutedEvent(): void $tableName = self::TABLE_NAME_USER; $uuid = $this->generateUuid(); $name = 'test'; - $conn->insert("INSERT INTO ${tableName} (`userId`, `name`) VALUES ('${uuid}', '${name}')"); + $conn->insert("INSERT INTO {$tableName} (`userId`, `name`) VALUES ('{$uuid}', '{$name}')"); $afterName = 'test2'; - $conn->update("UPDATE ${tableName} SET `name` = '${afterName}' WHERE `userId` = '${uuid}'"); - $conn->delete("DELETE FROM ${tableName} WHERE `userId` = '${uuid}'"); + $conn->update("UPDATE {$tableName} SET `name` = '{$afterName}' WHERE `userId` = '{$uuid}'"); + $conn->delete("DELETE FROM {$tableName} WHERE `userId` = '{$uuid}'"); $this->assertSame(5, $executedCount); } @@ -471,14 +471,14 @@ public function test_stale_reads(): void $timestamp = null; $db->runTransaction(function(Transaction $tx) use ($tableName, $uuid, &$timestamp) { $name = 'first'; - $tx->executeUpdate("INSERT INTO ${tableName} (`userId`, `name`) VALUES ('${uuid}', '${name}')"); + $tx->executeUpdate("INSERT INTO {$tableName} (`userId`, `name`) VALUES ('{$uuid}', '{$name}')"); $timestamp = $tx->commit(); }); $db->close(); $this->assertNotEmpty($timestamp); $timestampBound = new StrongRead(); - $rows = $conn->selectWithOptions("SELECT * FROM ${tableName} WHERE userID = ?", [$uuid], $timestampBound->transactionOptions()); + $rows = $conn->selectWithOptions("SELECT * FROM {$tableName} WHERE userID = ?", [$uuid], $timestampBound->transactionOptions()); $this->assertCount(1, $rows); $this->assertSame($uuid, $rows[0]['userId']); $this->assertSame('first', $rows[0]['name']); @@ -486,21 +486,21 @@ public function test_stale_reads(): void $oldDatetime = Carbon::instance($timestamp->get())->subSecond(); $timestampBound = new ReadTimestamp($oldDatetime); - $rows = $conn->selectWithOptions("SELECT * FROM ${tableName} WHERE userID = ?", [$uuid], $timestampBound->transactionOptions()); + $rows = $conn->selectWithOptions("SELECT * FROM {$tableName} WHERE userID = ?", [$uuid], $timestampBound->transactionOptions()); $this->assertEmpty($rows); $timestampBound = new ExactStaleness(10); - $rows = $conn->selectWithOptions("SELECT * FROM ${tableName} WHERE userID = ?", [$uuid], $timestampBound->transactionOptions()); + $rows = $conn->selectWithOptions("SELECT * FROM {$tableName} WHERE userID = ?", [$uuid], $timestampBound->transactionOptions()); $this->assertEmpty($rows); $timestampBound = new MaxStaleness(10); - $rows = $conn->selectWithOptions("SELECT * FROM ${tableName} WHERE userID = ?", [$uuid], $timestampBound->transactionOptions()); + $rows = $conn->selectWithOptions("SELECT * FROM {$tableName} WHERE userID = ?", [$uuid], $timestampBound->transactionOptions()); $this->assertCount(1, $rows); $this->assertSame($uuid, $rows[0]['userId']); $this->assertSame('first', $rows[0]['name']); $timestampBound = new MinReadTimestamp($oldDatetime); - $rows = $conn->selectWithOptions("SELECT * FROM ${tableName} WHERE userID = ?", [$uuid], $timestampBound->transactionOptions()); + $rows = $conn->selectWithOptions("SELECT * FROM {$tableName} WHERE userID = ?", [$uuid], $timestampBound->transactionOptions()); $this->assertCount(1, $rows); $this->assertSame($uuid, $rows[0]['userId']); $this->assertSame('first', $rows[0]['name']); @@ -518,7 +518,7 @@ public function testEventListenOrder(): void $tableName = self::TABLE_NAME_USER; $uuid = $this->generateUuid(); $name = 'test'; - $conn->insert("INSERT INTO ${tableName} (`userId`, `name`) VALUES ('${uuid}', '${name}')"); + $conn->insert("INSERT INTO {$tableName} (`userId`, `name`) VALUES ('{$uuid}', '{$name}')"); $this->assertCount(3, $receivedEventClasses); $this->assertSame(TransactionBeginning::class, $receivedEventClasses[0]); diff --git a/tests/Query/BuilderTest.php b/tests/Query/BuilderTest.php index 8cadfc9..fe5fe8e 100644 --- a/tests/Query/BuilderTest.php +++ b/tests/Query/BuilderTest.php @@ -568,7 +568,7 @@ public function testInsertDatetime(): void $qb = $conn->table($tableName); $row = $this->generateTestRow(); - $carbonMax = Carbon::maxValue(); + $carbonMax = Carbon::create(9999, 12, 31, 23, 59, 59, 'UTC'); $row['timestampTest'] = $carbonMax; $qb->insert($row); @@ -587,13 +587,13 @@ public function testWhereDatetime(): void $qb = $conn->table($tableName); $row = $this->generateTestRow(); - $carbonMax = Carbon::maxValue(); + $carbonMax = Carbon::create(9999, 12, 31, 23, 59, 59, 'UTC'); $row['timestampTest'] = $carbonMax; $qb->insert($row); - $this->assertSame(1, $qb->where('timestampTest', '=', Carbon::maxValue())->count()); - $this->assertSame(1, $qb->where('timestampTest', '<=', Carbon::maxValue())->count()); - $this->assertSame(0, $qb->where('timestampTest', '<', Carbon::maxValue())->count()); + $this->assertSame(1, $qb->where('timestampTest', '=', $carbonMax)->count()); + $this->assertSame(1, $qb->where('timestampTest', '<=', $carbonMax)->count()); + $this->assertSame(0, $qb->where('timestampTest', '<', $carbonMax)->count()); } /** From e2a56b2cffeb36beb51a1c303b85892f5292a431 Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Fri, 15 Mar 2024 15:05:17 +0900 Subject: [PATCH 2/7] bc --- CHANGELOG.md | 5 +++++ composer.json | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b8ce01..ecb3087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# v7.2.0 (2024-03-11) + +Added +- Laravel 11 Support (#200) + # v7.1.0 (2024-03-11) Changed diff --git a/composer.json b/composer.json index b9b1b4f..c11983f 100644 --- a/composer.json +++ b/composer.json @@ -8,15 +8,15 @@ {"name": "Takayasu Oyama", "email": "t-oyama@colopl.co.jp"} ], "require": { - "php": "^8.2", + "php": "^8.1", "ext-grpc": "*", "ext-json": "*", "laravel/framework": "^10.37.0|^11", "google/cloud-spanner": "^1.58.4", "grpc/grpc": "^1.42", - "symfony/cache": "~7", + "symfony/cache": "~6|~7", "symfony/deprecation-contracts": "~2", - "symfony/lock": "~7" + "symfony/lock": "~6|~7" }, "require-dev": { "orchestra/testbench": "~9", From e04c10336f5e3b2772a3a32b6636fd34fbe305c8 Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Fri, 15 Mar 2024 15:05:53 +0900 Subject: [PATCH 3/7] fix date --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecb3087..66a0b77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# v7.2.0 (2024-03-11) +# v7.2.0 (2024-03-15) Added - Laravel 11 Support (#200) From 9098c55e3142a1aa2b47140fd473399f0806c1b2 Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Fri, 15 Mar 2024 15:39:59 +0900 Subject: [PATCH 4/7] fix compatibility --- CHANGELOG.md | 12 +++++++- composer.json | 6 ++-- src/Query/Concerns/UsesMutations.php | 14 ++++++--- src/Query/Processor.php | 20 ------------ src/Schema/Blueprint.php | 9 ++---- src/Schema/Builder.php | 23 -------------- src/Schema/Grammar.php | 46 ---------------------------- 7 files changed, 26 insertions(+), 104 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66a0b77..f644aec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,17 @@ -# v7.2.0 (2024-03-15) +# v8.0.0 (2024-03-15) Added - Laravel 11 Support (#200) + - The following deprecated methods have been removed + - `Schema\Builder::getAllTables()` + - `Schema\Builder::getIndexListing()` + - `Schema\Grammar::compileTableExists()` + - `Schema\Grammar::compileGetAllTables()` + - `Schema\Grammar::compileColumnListing()` + - `Schema\Grammar::compileIndexListing()` + - `Query\Processor::processColumnListing()` + - `Query\Processor::processIndexListing()` + - `Blueprint::decimal()` can no longer specify `unsigned` flag. # v7.1.0 (2024-03-11) diff --git a/composer.json b/composer.json index c11983f..c73280d 100644 --- a/composer.json +++ b/composer.json @@ -11,12 +11,12 @@ "php": "^8.1", "ext-grpc": "*", "ext-json": "*", - "laravel/framework": "^10.37.0|^11", + "laravel/framework": "^11", "google/cloud-spanner": "^1.58.4", "grpc/grpc": "^1.42", - "symfony/cache": "~6|~7", + "symfony/cache": "~7", "symfony/deprecation-contracts": "~2", - "symfony/lock": "~6|~7" + "symfony/lock": "~7" }, "require-dev": { "orchestra/testbench": "~9", diff --git a/src/Query/Concerns/UsesMutations.php b/src/Query/Concerns/UsesMutations.php index 7d1afbf..14e530a 100644 --- a/src/Query/Concerns/UsesMutations.php +++ b/src/Query/Concerns/UsesMutations.php @@ -31,7 +31,7 @@ trait UsesMutations */ public function insertUsingMutation(array $values) { - $this->connection->insertUsingMutation($this->from, $values); + $this->connection->insertUsingMutation($this->getTableName(), $values); } /** @@ -40,7 +40,7 @@ public function insertUsingMutation(array $values) */ public function updateUsingMutation(array $values) { - $this->connection->updateUsingMutation($this->from, $values); + $this->connection->updateUsingMutation($this->getTableName(), $values); } /** @@ -49,7 +49,7 @@ public function updateUsingMutation(array $values) */ public function insertOrUpdateUsingMutation(array $values) { - $this->connection->insertOrUpdateUsingMutation($this->from, $values); + $this->connection->insertOrUpdateUsingMutation($this->getTableName(), $values); } /** @@ -58,6 +58,12 @@ public function insertOrUpdateUsingMutation(array $values) */ public function deleteUsingMutation($keys) { - $this->connection->deleteUsingMutation($this->from, $keys); + $this->connection->deleteUsingMutation($this->getTableName(), $keys); + } + + protected function getTableName(): string + { + assert(is_string($this->from)); + return $this->from; } } diff --git a/src/Query/Processor.php b/src/Query/Processor.php index 84c20bf..eb73cc0 100644 --- a/src/Query/Processor.php +++ b/src/Query/Processor.php @@ -63,16 +63,6 @@ protected function processColumn(mixed $value): mixed return $value; } - /** - * @inheritDoc - */ - public function processColumnListing($results) - { - return array_map(function ($result) { - return ((object) $result)->column_name; - }, $results); - } - /** * Process the results of a columns query. * @@ -94,16 +84,6 @@ public function processColumns($results) }, $results); } - /** - * @deprecated Use processIndexes($results) instead. - * @param array $results - * @return array - */ - public function processIndexListing($results) - { - return self::processIndexes($results); - } - /** * @param array $results * @return array diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index ced2ecb..4281444 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -138,10 +138,9 @@ public function binary($column, $length = null, $fixed = false) * @param string $column * @param int $total * @param int $places - * @param bool $unsigned * @return ColumnDefinition */ - public function decimal($column, $total = 38, $places = 9, $unsigned = false) + public function decimal($column, $total = 38, $places = 9) { if ($total !== 38) { $this->markAsNotSupported('decimal with precision other than 38'); @@ -151,11 +150,7 @@ public function decimal($column, $total = 38, $places = 9, $unsigned = false) $this->markAsNotSupported('decimal with scale other than 9'); } - if ($unsigned) { - $this->markAsNotSupported('unsigned decimal'); - } - - return parent::decimal($column, $total, $places, $unsigned); + return parent::decimal($column, $total, $places); } /** diff --git a/src/Schema/Builder.php b/src/Schema/Builder.php index 3bac270..05a04a5 100644 --- a/src/Schema/Builder.php +++ b/src/Schema/Builder.php @@ -40,18 +40,6 @@ class Builder extends BaseBuilder */ public static $defaultMorphKeyType = 'uuid'; - /** - * @deprecated Will be removed in a future Laravel version. - * - * @return list - */ - public function getAllTables() - { - return $this->connection->select( - $this->grammar->compileGetAllTables() - ); - } - /** * @inheritDoc Adds a parent key, for tracking interleaving * @@ -64,17 +52,6 @@ public function getTables() ); } - /** - * @deprecated Use getIndexes($table) instead - * - * @param string $table - * @return string[] - */ - public function getIndexListing($table) - { - return parent::getIndexes($table); - } - /** * @param string $table * @param string $name diff --git a/src/Schema/Grammar.php b/src/Schema/Grammar.php index bb3db52..6d7260b 100644 --- a/src/Schema/Grammar.php +++ b/src/Schema/Grammar.php @@ -40,18 +40,6 @@ class Grammar extends BaseGrammar */ protected $modifiers = ['Nullable', 'Default', 'UseSequence']; - /** - * Compile the query to determine if a table exists. - * - * @deprecated Will be removed in a future Laravel version. - * - * @return string - */ - public function compileTableExists() - { - return 'select * from information_schema.tables where table_schema = \'\' and table_name = ?'; - } - /** * Compile the query to determine the tables. * @@ -62,40 +50,6 @@ public function compileTables() return 'select `table_name` as name, `table_type` as type, `parent_table_name` as parent from information_schema.tables where table_schema = \'\' and table_type = \'BASE TABLE\''; } - /** - * @deprecated Will be removed in a future Laravel version. - * - * @return string - */ - public function compileGetAllTables() - { - return 'select `table_name` as name, `table_type` as type from information_schema.tables where table_schema = \'\' and table_type = \'BASE TABLE\''; - } - - /** - * Compile the query to determine the list of columns. - * - * @deprecated Will be removed in a future Laravel version. - * - * @return string - */ - public function compileColumnListing() - { - return 'select column_name as `column_name` from information_schema.columns where table_schema = \'\' and table_name = ?'; - } - - /** - * Compile the query to determine the list of indexes. - * - * @deprecated Use compileIndexes($table) instead. - * - * @return string - */ - public function compileIndexListing() - { - return 'select index_name as `index_name` from information_schema.indexes where table_schema = \'\' and table_name = ?'; - } - /** * Compile the query to determine the list of indexes. * From 0abbce863f3469f64d1992b99231a3894430a7a0 Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Fri, 15 Mar 2024 16:22:32 +0900 Subject: [PATCH 5/7] fix error --- tests/Query/BuilderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Query/BuilderTest.php b/tests/Query/BuilderTest.php index fe5fe8e..a6500cd 100644 --- a/tests/Query/BuilderTest.php +++ b/tests/Query/BuilderTest.php @@ -818,7 +818,7 @@ public function test_whereLike(): void $caughtException = $ex; } if (getenv('SPANNER_EMULATOR_HOST')) { - $this->assertStringContainsString('INTERNAL', $caughtException?->getMessage()); + $this->assertStringContainsString('Invalid UTF-8', $caughtException?->getMessage()); } else { $this->assertStringContainsString('Invalid request proto: an error was encountered during deserialization of the request proto.', $caughtException?->getMessage()); } From d3c35dd3e983cbbc334e0895e731b68027878d2f Mon Sep 17 00:00:00 2001 From: Takayasu Oyama Date: Tue, 19 Mar 2024 11:15:42 +0900 Subject: [PATCH 6/7] Apply suggestions from code review --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c73280d..c9d3327 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ {"name": "Takayasu Oyama", "email": "t-oyama@colopl.co.jp"} ], "require": { - "php": "^8.1", + "php": "^8.2", "ext-grpc": "*", "ext-json": "*", "laravel/framework": "^11", From 585fcf672f57b609786deddb1c60cf90cf1af69b Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Tue, 19 Mar 2024 12:08:41 +0900 Subject: [PATCH 7/7] fix doc --- src/Schema/Blueprint.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index 4281444..7289910 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -125,6 +125,7 @@ public function uuid($column = 'uuid') /** * @param string $column * @param int|null $length + * @param bool $fixed * @return ColumnDefinition */ public function binary($column, $length = null, $fixed = false)