Skip to content

Commit c286d28

Browse files
Merge pull request #208 from igun997/v1.x
update schema to support default schema on postgres & laravel 11 supoort on mysql
2 parents 7f8f377 + d357777 commit c286d28

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Meta/MySql/Schema.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ protected function resolveForeignTable($table, Blueprint $blueprint)
270270
*/
271271
public static function schemas(Connection $connection)
272272
{
273-
$schemas = $connection->getDoctrineSchemaManager()->listDatabases();
274-
273+
$schemas = $connection->select('SELECT schema_name FROM information_schema.schemata');
274+
$schemas = array_column($schemas, 'schema_name');
275275
return array_diff($schemas, [
276276
'information_schema',
277277
'sys',

src/Meta/Postgres/Schema.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Reliese\Meta\Postgres;
44

55
use Illuminate\Support\Arr;
6+
use Illuminate\Support\Facades\Config;
67
use Reliese\Meta\Blueprint;
78
use Illuminate\Support\Fluent;
89
use Illuminate\Database\Connection;
@@ -33,6 +34,11 @@ class Schema implements \Reliese\Meta\Schema
3334
*/
3435
protected $tables = [];
3536

37+
/**
38+
* @var mixed|null
39+
*/
40+
protected $schema_database = null;
41+
3642
/**
3743
* Mapper constructor.
3844
*
@@ -41,6 +47,10 @@ class Schema implements \Reliese\Meta\Schema
4147
*/
4248
public function __construct($schema, $connection)
4349
{
50+
$this->schema_database = Config::get("database.connections.pgsql.schema");
51+
if (!$this->schema_database){
52+
$this->schema_database = 'public';
53+
}
4454
$this->schema = $schema;
4555
$this->connection = $connection;
4656

@@ -82,7 +92,7 @@ protected function load()
8292
protected function fetchTables()
8393
{
8494
$rows = $this->arraify($this->connection->select(
85-
'SELECT * FROM pg_tables where schemaname=\'public\''
95+
"SELECT * FROM pg_tables where schemaname='$this->schema_database'"
8696
));
8797
$names = array_column($rows, 'tablename');
8898

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

0 commit comments

Comments
 (0)