From 51c32de39a6a22f4a5467468d649d9eb6f22373f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9E=A3=E5=86=85=20=E7=B9=81=E7=9B=B4?= Date: Mon, 22 Jan 2024 18:29:23 +0900 Subject: [PATCH] Not generating views for Postgres Fixes #230 --- src/Meta/Postgres/Schema.php | 38 ++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/Meta/Postgres/Schema.php b/src/Meta/Postgres/Schema.php index abe2c455..77f3e064 100644 --- a/src/Meta/Postgres/Schema.php +++ b/src/Meta/Postgres/Schema.php @@ -64,18 +64,18 @@ protected function load() // Note that "schema" refers to the database name, // not a pgsql schema. $this->connection->raw('\c '.$this->wrap($this->schema)); - $tables = $this->fetchTables($this->schema); + $tables = $this->fetchTables(); foreach ($tables as $table) { - $blueprint = new Blueprint($this->connection->getName(), $this->schema, $table); - $this->fillColumns($blueprint); - $this->fillConstraints($blueprint); - $this->tables[$table] = $blueprint; + $this->loadTable($table); + } + $views = $this->fetchViews(); + foreach ($views as $table) { + $this->loadTable($table, true); } $this->loaded = true; } /** - * @param string $schema * * @return array */ @@ -89,6 +89,20 @@ protected function fetchTables() return Arr::flatten($names); } + /** + * + * @return array + */ + protected function fetchViews() + { + $rows = $this->arraify($this->connection->select( + 'SELECT * FROM pg_views where schemaname=\'public\'', + )); + $names = array_column($rows, 'viewname'); + + return Arr::flatten($names); + } + /** * @param \Reliese\Meta\Blueprint $blueprint */ @@ -350,4 +364,16 @@ public function referencing(Blueprint $table) return $references; } + + /** + * @param string $table + * @param bool $isView + */ + protected function loadTable($table, $isView = false) + { + $blueprint = new Blueprint($this->connection->getName(), $this->schema, $table, $isView); + $this->fillColumns($blueprint); + $this->fillConstraints($blueprint); + $this->tables[$table] = $blueprint; + } }