Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not generating views for Postgres #270

Open
wants to merge 2 commits into
base: v1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions src/Meta/Postgres/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand Down Expand Up @@ -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;
}
}