diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fe69a93..815e2caa 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 internals so that it lines up with laravel 10.34.0. (#150) + # v6.0.0 (2023-11-22) Added 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..368245a9 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()); + [$levelBeingCommitted, $this->transactions] = [ + $this->transactions, + max(0, $this->transactions - 1), + ]; - $this->transactions = max(0, $this->transactions - 1); if ($this->isTransactionFinished()) { $this->currentTransaction = null; } - if ($this->afterCommitCallbacksShouldBeExecuted()) { - $this->transactionsManager?->commit($this->getName()); - } + $this->transactionsManager?->commit( + $this->getName(), + $levelBeingCommitted, + $this->transactions + ); } /** 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; diff --git a/tests/Schema/BuilderTest.php b/tests/Schema/BuilderTest.php index ae728370..73b91d3f 100644 --- a/tests/Schema/BuilderTest.php +++ b/tests/Schema/BuilderTest.php @@ -187,12 +187,56 @@ 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(); + $table = $this->generateTableName(class_basename(__CLASS__)); + + $sb->create($table, 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'] === $table, + ); + + $this->assertSame($table, $row['name']); + } + + public function test_getColumns(): void + { + $conn = $this->getDefaultConnection(); + $sb = $conn->getSchemaBuilder(); + $table = $this->generateTableName(class_basename(__CLASS__)); + + $sb->create($table, 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($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'); }); @@ -200,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 */