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

postgresql - Illuminate\Database\Schema\Builder::hasTable not honor to schema name #12856

Closed
boogiebug opened this issue Mar 25, 2016 · 3 comments

Comments

@boogiebug
Copy link

When I check for table existence on postgreSQL database, the builder query with the following statement:

select * from information_schema.tables where table_name = ?

Therefore, return as the table is existing if it is existed even in other schema. The better statement might be

select * from information_schema.tables where table_name = ? AND table_schema = ?

and pass the schema name as the second parameter.

@boogiebug
Copy link
Author

Here's the 'Quick-fixes' I put into the code:

File: Illuminate\Database\Schema\Builder.php

public function hasTable($table)
{
  $sql = $this->grammar->compileTableExists();

  $table = $this->connection->getTablePrefix().$table;
  $schema = $this->connection->getConfig('schema'); // <-- add this line

  return count($this->connection->select($sql, [$table, $schema])) > 0; // <-- add $schema in to the array parameter
}

File: Illuminate\Database\Schema\Grammars\PostgresGrammar.php

public function compileTableExists()
{
    return 'select * from information_schema.tables where table_name = ? and table_schema = ?'; // <-- add 'and table_schema = ?'
}

@themsaid
Copy link
Member

themsaid commented Apr 28, 2016

@GrahamCampbell this one was fixed here #13008

@GrahamCampbell
Copy link
Member

Thanks. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants