From 4caec32a183aa1f7eaeeb06e5b02cdc4e67cfbdb Mon Sep 17 00:00:00 2001 From: Takayasu Oyama Date: Thu, 11 Apr 2024 09:53:11 +0900 Subject: [PATCH] feat: laravel 11 support (#200) --- CHANGELOG.md | 17 +++++++++++++- Dockerfile | 2 +- composer.json | 12 +++++----- src/Query/ArrayValue.php | 30 ++++++++++++++++++++++++ src/Query/Builder.php | 15 ++++++++++++ src/Query/Grammar.php | 14 +++++++++++ src/Query/Processor.php | 20 ---------------- src/Schema/Blueprint.php | 12 ++++------ src/Schema/Builder.php | 23 ------------------- src/Schema/Grammar.php | 46 ------------------------------------- tests/ConnectionTest.php | 20 ++++++++-------- tests/Query/BuilderTest.php | 10 ++++---- 12 files changed, 101 insertions(+), 120 deletions(-) create mode 100644 src/Query/ArrayValue.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 37cc8e97..3b772b03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,19 @@ -# v7.2.0 (Not released yet) +# v8.0.0 (2024-04-11) + +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.2.0 (2024-03-27) Added - Support for `Query\Builder::upsert()` (#203) diff --git a/Dockerfile b/Dockerfile index 37c2809a..26856379 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 8ca7619d..c9d33275 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": "^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 00000000..5484d4bd --- /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 6927adbc..ee59be00 100644 --- a/src/Query/Grammar.php +++ b/src/Query/Grammar.php @@ -54,6 +54,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/Query/Processor.php b/src/Query/Processor.php index 84c20bfb..eb73cc07 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 0d3c8969..72899107 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -125,9 +125,10 @@ public function uuid($column = 'uuid') /** * @param string $column * @param int|null $length + * @param bool $fixed * @return ColumnDefinition */ - public function binary($column, $length = null) + public function binary($column, $length = null, $fixed = false) { $length = $length ?: Builder::$defaultBinaryLength; @@ -138,10 +139,9 @@ public function binary($column, $length = null) * @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 +151,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 3bac2708..05a04a55 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 bb3db523..6d7260bb 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. * diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 95f46e54..4e71ebbe 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 a6790737..b9264e01 100644 --- a/tests/Query/BuilderTest.php +++ b/tests/Query/BuilderTest.php @@ -567,7 +567,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); @@ -658,13 +658,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()); } /**