diff --git a/src/Query/Processor.php b/src/Query/Processor.php index 335b425..99e1379 100644 --- a/src/Query/Processor.php +++ b/src/Query/Processor.php @@ -81,6 +81,27 @@ public function processSelect(Builder $query, $results): array return $results; } + /** + * @inheritDoc + */ + public function processTables($results) + { + return array_map(function ($result) { + $result = (object) $result; + + return [ + 'name' => $result->name, + 'schema' => $result->schema === '' ? $result->schema : null, + 'schema_qualified_name' => $result->schema !== '' ? $result->schema.'.'.$result->name : $result->name, + 'size' => isset($result->size) ? (int) $result->size : null, + 'comment' => null, + 'collation' => null, + 'engine' => null, + 'parent' => $result->parent, + ]; + }, $results); + } + /** * @template TValue of mixed * @param TValue $value @@ -100,41 +121,27 @@ protected function processColumn(mixed $value): mixed } /** - * Process the results of a columns query. - * * {@inheritDoc} - * @param array> $results - * @return array + * @param list $results */ 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, + 'type_name' => (string) preg_replace("/\([^)]+\)/", "", $result['SPANNER_TYPE']), 'nullable' => $result['IS_NULLABLE'] !== 'NO', 'default' => $result['COLUMN_DEFAULT'], 'auto_increment' => false, + 'generation' => null, 'comment' => null, ]; }, $results); } /** - * {@inheritDoc} - * @param list> $results - * @return list, type: string, unique: bool, primary: bool}> + * @inheritDoc */ public function processIndexes($results) { @@ -152,9 +159,7 @@ public function processIndexes($results) } /** - * {@inheritDoc} - * @param array{key_name: string}&array $results - * @return array + * @inheritDoc */ public function processForeignKeys($results) { diff --git a/src/Schema/Builder.php b/src/Schema/Builder.php index 6eb5d27..0601120 100644 --- a/src/Schema/Builder.php +++ b/src/Schema/Builder.php @@ -19,6 +19,7 @@ use Closure; use Colopl\Spanner\Connection; +use Colopl\Spanner\Query\Processor; use Illuminate\Database\Schema\Builder as BaseBuilder; /** @@ -41,17 +42,15 @@ class Builder extends BaseBuilder public static $defaultMorphKeyType = 'uuid'; /** - * @param null $schema * @inheritDoc Adds a parent key, for tracking interleaving - * - * @return list + * @return list */ public function getTables($schema = null) { - /** @var list */ - return $this->connection->select( - $this->grammar->compileTables(null), - ); + $results = $this->connection->select($this->grammar->compileTables($schema)); + assert(array_is_list($results)); + /** @phpstan-ignore return.type */ + return $this->connection->getPostProcessor()->processTables($results); } /** @@ -73,7 +72,7 @@ public function dropIndex($table, $name) */ public function dropIndexIfExist($table, $name) { - if (in_array($name, $this->getIndexes($table), true)) { + if (in_array($name, $this->getIndexListing($table), true)) { $blueprint = $this->createBlueprint($table); $blueprint->dropIndex($name); $this->build($blueprint); diff --git a/src/Schema/Grammar.php b/src/Schema/Grammar.php index bec2bf1..a08d0cc 100644 --- a/src/Schema/Grammar.php +++ b/src/Schema/Grammar.php @@ -47,7 +47,14 @@ class Grammar extends BaseGrammar */ public function compileTables($schema) { - 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\''; + if ($schema === null || (is_array($schema) && count($schema) === 0)) { + $schema = ''; + } + + return + 'select `table_name` as name, `table_type` as type, `parent_table_name` as parent, `table_schema` as `schema` ' . + 'from information_schema.tables where table_type = \'BASE TABLE\' ' . + 'and table_schema in (' . $this->quoteString($schema) . ')'; } /** diff --git a/tests/Schema/BuilderTestLast.php b/tests/Schema/BuilderTestLast.php index 66231e9..7bf03c7 100644 --- a/tests/Schema/BuilderTestLast.php +++ b/tests/Schema/BuilderTestLast.php @@ -235,12 +235,12 @@ public function test_getColumns(): void $this->assertSame([ 'name' => 'id', - 'type_name' => 'STRING', 'type' => 'STRING(36)', - 'collation' => null, + 'type_name' => 'STRING', 'nullable' => false, 'default' => null, 'auto_increment' => false, + 'generation' => null, 'comment' => null, ], Arr::first($sb->getColumns($table))); }