From ce3954ab6d293051e93652813a2813d05083db17 Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Wed, 29 Nov 2023 10:15:20 +0900 Subject: [PATCH 1/7] fix: laravel 10.34.0 changed transaction internals --- composer.json | 2 +- src/Concerns/ManagesTransactions.php | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index d1c4bb56..268654f1 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "php": "^8.1", "ext-grpc": "*", "ext-json": "*", - "laravel/framework": "^10.32.0", + "laravel/framework": "^10.34.2", "google/cloud-spanner": "^1.58.4", "grpc/grpc": "^1.42", "symfony/cache": "~6", diff --git a/src/Concerns/ManagesTransactions.php b/src/Concerns/ManagesTransactions.php index 29d9440b..204c7c2f 100644 --- a/src/Concerns/ManagesTransactions.php +++ b/src/Concerns/ManagesTransactions.php @@ -141,16 +141,20 @@ protected function performSpannerCommit(): void $this->currentTransaction->commit(); } - $this->transactionsManager?->stageTransactions($this->getName()); - - $this->transactions = max(0, $this->transactions - 1); if ($this->isTransactionFinished()) { $this->currentTransaction = null; } - if ($this->afterCommitCallbacksShouldBeExecuted()) { - $this->transactionsManager?->commit($this->getName()); - } + [$levelBeingCommitted, $this->transactions] = [ + $this->transactions, + max(0, $this->transactions - 1), + ]; + + $this->transactionsManager?->commit( + $this->getName(), + $levelBeingCommitted, + $this->transactions + ); } /** From 816706f354710a1a8564fc10dc2839161972f344 Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Wed, 29 Nov 2023 10:37:07 +0900 Subject: [PATCH 2/7] update change log --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fe69a93..a304137e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ Added - Add support for [NUMERIC](https://cloud.google.com/spanner/docs/reference/standard-sql/data-types#numeric_type) column type. (#145) +Fixed +- Match transaction internals so that it lines up with laravel 10.34.0. (#150) + # v6.0.0 (2023-11-22) Added From 3ac3b55be1740fd17c4492a1e80e29132978e6fc Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Wed, 29 Nov 2023 11:01:03 +0900 Subject: [PATCH 3/7] fix timing --- src/Concerns/ManagesTransactions.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Concerns/ManagesTransactions.php b/src/Concerns/ManagesTransactions.php index 204c7c2f..368245a9 100644 --- a/src/Concerns/ManagesTransactions.php +++ b/src/Concerns/ManagesTransactions.php @@ -141,15 +141,15 @@ protected function performSpannerCommit(): void $this->currentTransaction->commit(); } - if ($this->isTransactionFinished()) { - $this->currentTransaction = null; - } - [$levelBeingCommitted, $this->transactions] = [ $this->transactions, max(0, $this->transactions - 1), ]; + if ($this->isTransactionFinished()) { + $this->currentTransaction = null; + } + $this->transactionsManager?->commit( $this->getName(), $levelBeingCommitted, From 203b65812299658cf28bed3154f117d5090b7ba1 Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Wed, 29 Nov 2023 14:14:32 +0900 Subject: [PATCH 4/7] fix tests --- src/Query/Processor.php | 21 +++++++++++++++++++++ src/Schema/Builder.php | 16 ++-------------- src/Schema/Grammar.php | 34 ++++++++++++++++++++++++++++++++++ tests/Query/BuilderTest.php | 2 +- 4 files changed, 58 insertions(+), 15 deletions(-) diff --git a/src/Query/Processor.php b/src/Query/Processor.php index d40c074c..ec9106ec 100644 --- a/src/Query/Processor.php +++ b/src/Query/Processor.php @@ -56,6 +56,27 @@ public function processColumnListing($results) }, $results); } + /** + * Process the results of a columns query. + * + * @inheritDoc + */ + public function processColumns($results) + { + return array_map(static function (array $result) { + return [ + 'name' => $result['COLUMN_NAME'], + 'type_name' => preg_replace("/\([^)]+\)/", "", $result['SPANNER_TYPE']), + 'type' => $result['SPANNER_TYPE'], + 'collation' => null, + 'nullable' => $result['IS_NULLABLE'] !== 'NO', + 'default' => $result['COLUMN_DEFAULT'], + 'auto_increment' => false, + 'comment' => null, + ]; + }, $results); + } + /** * @param array $results * @return array diff --git a/src/Schema/Builder.php b/src/Schema/Builder.php index 1c9c911d..1e922692 100644 --- a/src/Schema/Builder.php +++ b/src/Schema/Builder.php @@ -35,6 +35,8 @@ class Builder extends BaseBuilder /** + * @deprecated Will be removed in a future Laravel version. + * * @return list */ public function getAllTables() @@ -44,20 +46,6 @@ public function getAllTables() ); } - /** - * @inheritDoc - */ - public function getColumnListing($table) - { - $table = $this->connection->getTablePrefix().$table; - - $results = $this->connection->select( - $this->grammar->compileColumnListing(), [$table] - ); - - return $this->connection->getPostProcessor()->processColumnListing($results); - } - /** * @param string $table * @return string[] diff --git a/src/Schema/Grammar.php b/src/Schema/Grammar.php index 1b69c67d..1499d9cd 100644 --- a/src/Schema/Grammar.php +++ b/src/Schema/Grammar.php @@ -40,6 +40,10 @@ class Grammar extends BaseGrammar protected $modifiers = ['Nullable', 'Default']; /** + * Compile the query to determine if a table exists. + * + * @deprecated Will be removed in a future Laravel version. + * * @return string */ public function compileTableExists() @@ -48,6 +52,18 @@ public function compileTableExists() } /** + * Compile the query to determine the tables. + * + * @return string + */ + public function compileTables() + { + return 'select `table_name` as name 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() @@ -56,6 +72,10 @@ public function compileGetAllTables() } /** + * Compile the query to determine the list of columns. + * + * @deprecated Will be removed in a future Laravel version. + * * @return string */ public function compileColumnListing() @@ -73,6 +93,20 @@ 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 columns. + * + * @param string $table + * @return string + */ + public function compileColumns($table) + { + return sprintf( + 'select * from information_schema.columns where table_schema = \'\' and table_name = %s', + $this->quoteString($table), + ); + } + /** * Compile a create table command. * diff --git a/tests/Query/BuilderTest.php b/tests/Query/BuilderTest.php index 400e2ca4..9ac8c82f 100644 --- a/tests/Query/BuilderTest.php +++ b/tests/Query/BuilderTest.php @@ -32,7 +32,7 @@ class BuilderTest extends TestCase { - public function testInsert(): void + public function test_insert(): void { $conn = $this->getDefaultConnection(); $tableName = self::TABLE_NAME_USER; From b8bfd792ea3930605e2861d92ca80fdf7720cc76 Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Wed, 29 Nov 2023 15:12:59 +0900 Subject: [PATCH 5/7] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a304137e..815e2caa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Added - Add support for [NUMERIC](https://cloud.google.com/spanner/docs/reference/standard-sql/data-types#numeric_type) column type. (#145) Fixed -- Match transaction internals so that it lines up with laravel 10.34.0. (#150) +- Match internals so that it lines up with laravel 10.34.0. (#150) # v6.0.0 (2023-11-22) From 4c04616e98dc4b7186b4959b68d5eedb7d8518a9 Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Wed, 29 Nov 2023 15:17:56 +0900 Subject: [PATCH 6/7] add more tests --- tests/Schema/BuilderTest.php | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/Schema/BuilderTest.php b/tests/Schema/BuilderTest.php index ae728370..08803601 100644 --- a/tests/Schema/BuilderTest.php +++ b/tests/Schema/BuilderTest.php @@ -187,6 +187,47 @@ public function testCreateInterleavedTable(): void $this->assertTrue($sb->hasTable(self::TABLE_NAME_RELATION_CHILD_INTERLEAVED)); } + public function test_getTables(): void + { + $conn = $this->getDefaultConnection(); + $sb = $conn->getSchemaBuilder(); + + $sb->create(self::TABLE_NAME_CREATED, function (Blueprint $table) { + $table->uuid('id'); + $table->primary('id'); + }); + + /** @var array{ name: string, type: string } $row */ + $row = Arr::first( + $sb->getTables(), + static fn (array $row): bool => $row['name'] === self::TABLE_NAME_CREATED, + ); + + $this->assertSame(self::TABLE_NAME_CREATED, $row['name']); + } + + public function test_getColumns(): void + { + $conn = $this->getDefaultConnection(); + $sb = $conn->getSchemaBuilder(); + + $sb->create(self::TABLE_NAME_CREATED, function (Blueprint $table) { + $table->uuid('id'); + $table->primary('id'); + }); + + $this->assertSame([ + 'name' => 'id', + 'type_name' => 'STRING', + 'type' => 'STRING(36)', + 'collation' => null, + 'nullable' => false, + 'default' => null, + 'auto_increment' => false, + 'comment' => null, + ], Arr::first($sb->getColumns(self::TABLE_NAME_CREATED))); + } + public function test_getAllTables(): void { $conn = $this->getDefaultConnection(); From 2cb1080f8e47a264b4e80419e3bf3de06131faa0 Mon Sep 17 00:00:00 2001 From: Taka Oyama Date: Wed, 29 Nov 2023 15:41:32 +0900 Subject: [PATCH 7/7] fix test --- tests/Schema/BuilderTest.php | 19 +++++++++++-------- tests/TestCase.php | 5 +++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/tests/Schema/BuilderTest.php b/tests/Schema/BuilderTest.php index 08803601..73b91d3f 100644 --- a/tests/Schema/BuilderTest.php +++ b/tests/Schema/BuilderTest.php @@ -191,8 +191,9 @@ public function test_getTables(): void { $conn = $this->getDefaultConnection(); $sb = $conn->getSchemaBuilder(); + $table = $this->generateTableName(class_basename(__CLASS__)); - $sb->create(self::TABLE_NAME_CREATED, function (Blueprint $table) { + $sb->create($table, function (Blueprint $table) { $table->uuid('id'); $table->primary('id'); }); @@ -200,18 +201,19 @@ public function test_getTables(): void /** @var array{ name: string, type: string } $row */ $row = Arr::first( $sb->getTables(), - static fn (array $row): bool => $row['name'] === self::TABLE_NAME_CREATED, + static fn (array $row): bool => $row['name'] === $table, ); - $this->assertSame(self::TABLE_NAME_CREATED, $row['name']); + $this->assertSame($table, $row['name']); } public function test_getColumns(): void { $conn = $this->getDefaultConnection(); $sb = $conn->getSchemaBuilder(); + $table = $this->generateTableName(class_basename(__CLASS__)); - $sb->create(self::TABLE_NAME_CREATED, function (Blueprint $table) { + $sb->create($table, function (Blueprint $table) { $table->uuid('id'); $table->primary('id'); }); @@ -225,15 +227,16 @@ public function test_getColumns(): void 'default' => null, 'auto_increment' => false, 'comment' => null, - ], Arr::first($sb->getColumns(self::TABLE_NAME_CREATED))); + ], Arr::first($sb->getColumns($table))); } public function test_getAllTables(): void { $conn = $this->getDefaultConnection(); $sb = $conn->getSchemaBuilder(); + $table = $this->generateTableName(class_basename(__CLASS__)); - $sb->create(self::TABLE_NAME_CREATED, function (Blueprint $table) { + $sb->create($table, function (Blueprint $table) { $table->uuid('id'); $table->primary('id'); }); @@ -241,10 +244,10 @@ public function test_getAllTables(): void /** @var array{ name: string, type: string } $row */ $row = Arr::first( $sb->getAllTables(), - static fn (array $row): bool => $row['name'] === self::TABLE_NAME_CREATED, + static fn (array $row): bool => $row['name'] === $table, ); - $this->assertSame(self::TABLE_NAME_CREATED, $row['name']); + $this->assertSame($table, $row['name']); $this->assertSame('BASE TABLE', $row['type']); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 4a98154b..7c0a859c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -41,6 +41,11 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase protected const TABLE_NAME_ITEM_TAG = 'ItemTag'; protected const TABLE_NAME_ARRAY_TEST = 'ArrayTest'; + protected function generateTableName(string $prefix): string + { + return $prefix . '_' . date('Ymd_His_v'); + } + /** * @return string */