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

Deprecate AbstractSchemaManager::getSchemaSearchPaths() #4821

Merged
merged 1 commit into from
Sep 29, 2021
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
7 changes: 7 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ awareness about deprecated code.

# Upgrade to 3.2

## Deprecated `AbstractSchemaManager::getSchemaSearchPaths()`.

1. The `AbstractSchemaManager::getSchemaSearchPaths()` method has been deprecated.
2. Relying on `AbstractSchemaManager::createSchemaConfig()` populating the schema name for those database
platforms that don't support schemas (currently, all except for PostgreSQL) is deprecated.
3. Relying on `Schema` using "public" as the default name is deprecated.

## Deprecated `AbstractAsset::getFullQualifiedName()`.

The `AbstractAsset::getFullQualifiedName()` method has been deprecated. Use `::getNamespaceName()`
Expand Down
5 changes: 5 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@
See https://github.com/doctrine/dbal/pull/4814
-->
<referencedMethod name="Doctrine\DBAL\Schema\AbstractAsset::getFullQualifiedName"/>
<!--
TODO: remove in 4.0.0
See https://github.com/doctrine/dbal/pull/4821
-->
<referencedMethod name="Doctrine\DBAL\Schema\AbstractSchemaManager::getSchemaSearchPaths"/>
</errorLevel>
</DeprecatedMethod>
<DeprecatedProperty>
Expand Down
8 changes: 8 additions & 0 deletions src/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1172,12 +1172,20 @@ public function createSchemaConfig()
* For databases that don't support subschema/namespaces this method
* returns the name of the currently connected database.
*
* @deprecated
*
* @return string[]
*
* @throws Exception
*/
public function getSchemaSearchPaths()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4821',
'AbstractSchemaManager::getSchemaSearchPaths() is deprecated.'
);

$database = $this->_conn->getDatabase();

if ($database !== null) {
Expand Down
31 changes: 28 additions & 3 deletions src/Schema/PostgreSQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,17 @@ public function listSchemaNames(): array

/**
* {@inheritDoc}
*
* @deprecated
*/
public function getSchemaSearchPaths()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4821',
'PostgreSQLSchemaManager::getSchemaSearchPaths() is deprecated.'
);

$params = $this->_conn->getParams();

$searchPaths = $this->_conn->fetchOne('SHOW search_path');
Expand All @@ -101,6 +109,8 @@ public function getSchemaSearchPaths()
* @internal The method should be only used from within the PostgreSQLSchemaManager class hierarchy.
*
* @return string[]
*
* @throws Exception
*/
public function getExistingSchemaSearchPaths()
{
Expand All @@ -111,6 +121,20 @@ public function getExistingSchemaSearchPaths()
return $this->existingSchemaPaths;
}

/**
* Returns the name of the current schema.
*
* @return string|null
*
* @throws Exception
*/
protected function getCurrentSchema()
{
$schemas = $this->getExistingSchemaSearchPaths();

return array_shift($schemas);
}

/**
* Sets or resets the order of the existing schemas in the current search path of the user.
*
Expand All @@ -119,6 +143,8 @@ public function getExistingSchemaSearchPaths()
* @internal The method should be only used from within the PostgreSQLSchemaManager class hierarchy.
*
* @return void
*
* @throws Exception
*/
public function determineExistingSchemaSearchPaths()
{
Expand Down Expand Up @@ -200,10 +226,9 @@ protected function _getPortableUserDefinition($user)
*/
protected function _getPortableTableDefinition($table)
{
$schemas = $this->getExistingSchemaSearchPaths();
$firstSchema = array_shift($schemas);
$currentSchema = $this->getCurrentSchema();

if ($table['schema_name'] === $firstSchema) {
if ($table['schema_name'] === $currentSchema) {
return $table['table_name'];
}

Expand Down
9 changes: 9 additions & 0 deletions src/Schema/SqliteSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\Types\StringType;
use Doctrine\DBAL\Types\TextType;
use Doctrine\DBAL\Types\Type;
use Doctrine\Deprecations\Deprecation;

use function array_change_key_case;
use function array_map;
Expand Down Expand Up @@ -580,9 +581,17 @@ public function createComparator(): Comparator

/**
* {@inheritDoc}
*
* @deprecated
*/
public function getSchemaSearchPaths()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4821',
'SqliteSchemaManager::getSchemaSearchPaths() is deprecated.'
);

// SQLite does not support schemas or databases
return [];
}
Expand Down