diff --git a/UPGRADE.md b/UPGRADE.md
index ed30555dbde..5239d3dd4aa 100644
--- a/UPGRADE.md
+++ b/UPGRADE.md
@@ -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()`
diff --git a/psalm.xml.dist b/psalm.xml.dist
index 2cfb15aa1bc..b4a45d930a9 100644
--- a/psalm.xml.dist
+++ b/psalm.xml.dist
@@ -164,6 +164,11 @@
See https://github.com/doctrine/dbal/pull/4814
-->
+
+
diff --git a/src/Schema/AbstractSchemaManager.php b/src/Schema/AbstractSchemaManager.php
index 3b2e2fbf4dc..3c0b882d9e4 100644
--- a/src/Schema/AbstractSchemaManager.php
+++ b/src/Schema/AbstractSchemaManager.php
@@ -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) {
diff --git a/src/Schema/PostgreSQLSchemaManager.php b/src/Schema/PostgreSQLSchemaManager.php
index a015577f262..f112400df1a 100644
--- a/src/Schema/PostgreSQLSchemaManager.php
+++ b/src/Schema/PostgreSQLSchemaManager.php
@@ -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');
@@ -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()
{
@@ -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.
*
@@ -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()
{
@@ -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'];
}
diff --git a/src/Schema/SqliteSchemaManager.php b/src/Schema/SqliteSchemaManager.php
index 1895fc4e1dd..a96476f6106 100644
--- a/src/Schema/SqliteSchemaManager.php
+++ b/src/Schema/SqliteSchemaManager.php
@@ -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;
@@ -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 [];
}