From 0a26661949db13fb3f3c878177f77d8d3a8fa987 Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Mon, 25 Apr 2016 20:10:21 +0300 Subject: [PATCH] Fix postgres Schema::hastable (#13008) --- .../Database/PostgresConnection.php | 15 ++++++++++++ .../Schema/Grammars/PostgresGrammar.php | 2 +- .../Database/Schema/PostgresBuilder.php | 23 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 src/Illuminate/Database/Schema/PostgresBuilder.php diff --git a/src/Illuminate/Database/PostgresConnection.php b/src/Illuminate/Database/PostgresConnection.php index f12ec8934e07..779888d0e53c 100755 --- a/src/Illuminate/Database/PostgresConnection.php +++ b/src/Illuminate/Database/PostgresConnection.php @@ -2,6 +2,7 @@ namespace Illuminate\Database; +use Illuminate\Database\Schema\PostgresBuilder; use Doctrine\DBAL\Driver\PDOPgSql\Driver as DoctrineDriver; use Illuminate\Database\Query\Processors\PostgresProcessor; use Illuminate\Database\Query\Grammars\PostgresGrammar as QueryGrammar; @@ -9,6 +10,20 @@ class PostgresConnection extends Connection { + /** + * Get a schema builder instance for the connection. + * + * @return \Illuminate\Database\Schema\PostgresBuilder + */ + public function getSchemaBuilder() + { + if (is_null($this->schemaGrammar)) { + $this->useDefaultSchemaGrammar(); + } + + return new PostgresBuilder($this); + } + /** * Get the default query grammar instance. * diff --git a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php index a02bae657377..20de4068e4b0 100755 --- a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php @@ -28,7 +28,7 @@ class PostgresGrammar extends Grammar */ public function compileTableExists() { - return 'select * from information_schema.tables where table_name = ?'; + return 'select * from information_schema.tables where table_schema = ? and table_name = ?'; } /** diff --git a/src/Illuminate/Database/Schema/PostgresBuilder.php b/src/Illuminate/Database/Schema/PostgresBuilder.php new file mode 100755 index 000000000000..20abc0fe1e48 --- /dev/null +++ b/src/Illuminate/Database/Schema/PostgresBuilder.php @@ -0,0 +1,23 @@ +grammar->compileTableExists(); + + $schema = $this->connection->getConfig('schema'); + + $table = $this->connection->getTablePrefix().$table; + + return count($this->connection->select($sql, [$schema, $table])) > 0; + } +}