Skip to content

Commit

Permalink
Merge pull request #728 from challgren/fix-pgsql-schema
Browse files Browse the repository at this point in the history
Correcting getGlobalSchemaName to use the correct schema
  • Loading branch information
markstory authored Aug 29, 2024
2 parents 6047ee0 + 4cf0b0f commit 0716a4b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1506,8 +1506,9 @@ protected function getSchemaName(string $tableName): array
protected function getGlobalSchemaName(): string
{
$options = $this->getOptions();
$config = $options['connection']->config() ?? [];

return empty($options['schema']) ? 'public' : $options['schema'];
return empty($config['schema']) ? 'public' : $config['schema'];
}

/**
Expand Down
24 changes: 24 additions & 0 deletions tests/TestCase/Db/Adapter/PostgresAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,30 @@ public function testQuoteSchemaName()
$this->assertEquals('"schema.schema"', $this->adapter->quoteSchemaName('schema.schema'));
}

public function testGetGlobalSchemaName()
{
$config = ConnectionManager::getConfig('test');
$config['schema'] = 'test_schema';
ConnectionManager::setConfig('test-schema', $config);
// Emulate the results of Util::parseDsn()
$this->config = [
'adapter' => 'postgres',
'connection' => ConnectionManager::get('test-schema'),
'database' => $config['database'],
];

$this->adapter = new PostgresAdapter($this->config, $this->getConsoleIo());

$this->adapter->dropAllSchemas();
$this->adapter->createSchema('test_schema');

$this->adapter->disconnect();

$this->assertEquals('"test_schema"."table"', $this->adapter->quoteTableName('table'));

ConnectionManager::drop('test-schema');
}

public function testQuoteTableName()
{
$this->assertEquals('"public"."table"', $this->adapter->quoteTableName('table'));
Expand Down

0 comments on commit 0716a4b

Please sign in to comment.