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

Correcting getGlobalSchemaName to use the correct schema #728

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 getGlobalSchemaName(): string
{
$options = $this->getOptions();
$config = $options['connection']->config() ?? [];

Check warning on line 1509 in src/Db/Adapter/PostgresAdapter.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Adapter/PostgresAdapter.php#L1509

Added line #L1509 was not covered by tests

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

Check warning on line 1511 in src/Db/Adapter/PostgresAdapter.php

View check run for this annotation

Codecov / codecov/patch

src/Db/Adapter/PostgresAdapter.php#L1511

Added line #L1511 was not covered by tests
}

/**
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
Loading