Skip to content

Commit

Permalink
Merge pull request #208 from igun997/v1.x
Browse files Browse the repository at this point in the history
update schema to support default schema on postgres & laravel 11 supoort on mysql
  • Loading branch information
finiteinfinity authored Jun 6, 2024
2 parents 7f8f377 + d357777 commit c286d28
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Meta/MySql/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ protected function resolveForeignTable($table, Blueprint $blueprint)
*/
public static function schemas(Connection $connection)
{
$schemas = $connection->getDoctrineSchemaManager()->listDatabases();

$schemas = $connection->select('SELECT schema_name FROM information_schema.schemata');
$schemas = array_column($schemas, 'schema_name');
return array_diff($schemas, [
'information_schema',
'sys',
Expand Down
14 changes: 12 additions & 2 deletions src/Meta/Postgres/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Reliese\Meta\Postgres;

use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Config;
use Reliese\Meta\Blueprint;
use Illuminate\Support\Fluent;
use Illuminate\Database\Connection;
Expand Down Expand Up @@ -33,6 +34,11 @@ class Schema implements \Reliese\Meta\Schema
*/
protected $tables = [];

/**
* @var mixed|null
*/
protected $schema_database = null;

/**
* Mapper constructor.
*
Expand All @@ -41,6 +47,10 @@ class Schema implements \Reliese\Meta\Schema
*/
public function __construct($schema, $connection)
{
$this->schema_database = Config::get("database.connections.pgsql.schema");
if (!$this->schema_database){
$this->schema_database = 'public';
}
$this->schema = $schema;
$this->connection = $connection;

Expand Down Expand Up @@ -82,7 +92,7 @@ protected function load()
protected function fetchTables()
{
$rows = $this->arraify($this->connection->select(
'SELECT * FROM pg_tables where schemaname=\'public\''
"SELECT * FROM pg_tables where schemaname='$this->schema_database'"
));
$names = array_column($rows, 'tablename');

Expand All @@ -96,7 +106,7 @@ protected function fillColumns(Blueprint $blueprint)
{
$rows = $this->arraify($this->connection->select(
'SELECT * FROM information_schema.columns '.
'WHERE table_schema=\'public\''.
"WHERE table_schema='$this->schema_database'".
'AND table_name='.$this->wrap($blueprint->table())
));
foreach ($rows as $column) {
Expand Down

0 comments on commit c286d28

Please sign in to comment.