From 3dbbd0ec4780dcc99efb2adf809855c016a5fbc4 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 1 Apr 2021 18:48:56 -0700 Subject: [PATCH] [GH-4503] Remove deprecated in schema- and namespace-related APIs --- UPGRADE.md | 14 ++++ psalm.xml.dist | 9 --- src/Platforms/AbstractPlatform.php | 19 ------ src/Platforms/PostgreSQL94Platform.php | 18 ----- src/Platforms/SQLServer2012Platform.php | 15 ---- src/Schema/AbstractSchemaManager.php | 68 +------------------ src/Schema/PostgreSQLSchemaManager.php | 48 +------------ src/Schema/SQLServerSchemaManager.php | 18 ----- .../Schema/PostgreSQLSchemaManagerTest.php | 6 +- .../SchemaManagerFunctionalTestCase.php | 25 +------ 10 files changed, 20 insertions(+), 220 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index d3ed5027120..745b0c783bb 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,19 @@ # Upgrade to 4.0 +## Removed schema- and namespace-related methods + +The following schema- and namespace-related methods have been removed: + +- `AbstractPlatform::getListNamespacesSQL()`, +- `AbstractSchemaManager::listNamespaceNames()`, +- `AbstractSchemaManager::getPortableNamespacesList()`, +- `AbstractSchemaManager::getPortableNamespaceDefinition()`, +- `PostgreSQLSchemaManager::getSchemaNames()`. + +## `PostgreSQLSchemaManager` methods have been made protected. + +`PostgreSQLSchemaManager::getExistingSchemaSearchPaths()` and `::determineExistingSchemaSearchPaths()` have been made protected. + ## Removed the `$driverOptions` argument of `PDO\Statement::bindParam()` and `PDO\SQLSrv\Statement::bindParam()` The `$driverOptions` argument of `PDO\Statement::bindParam()` and `PDO\SQLSrv\Statement::bindParam()` has been removed. The specifics of binding a parameter to the statement should be specified using the `$type` argument. diff --git a/psalm.xml.dist b/psalm.xml.dist index 6a0f40d82d0..d0d742e3518 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -59,15 +59,6 @@ See https://github.com/doctrine/dbal/issues/4510 --> - - - - - - diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index f1fd939a12c..9e262b3f4ac 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -2505,25 +2505,6 @@ public function getListDatabasesSQL(): string throw NotSupported::new(__METHOD__); } - /** - * Returns the SQL statement for retrieving the namespaces defined in the database. - * - * @deprecated Use {@link AbstractSchemaManager::listSchemaNames()} instead. - * - * @throws Exception If not supported on this platform. - */ - public function getListNamespacesSQL(): string - { - Deprecation::triggerIfCalledFromOutside( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/issues/4503', - 'AbstractPlatform::getListNamespacesSQL() is deprecated,' - . ' use AbstractSchemaManager::listSchemaNames() instead.' - ); - - throw NotSupported::new(__METHOD__); - } - /** * @throws Exception If not supported on this platform. */ diff --git a/src/Platforms/PostgreSQL94Platform.php b/src/Platforms/PostgreSQL94Platform.php index e6ed2efe0ba..592bae551e7 100644 --- a/src/Platforms/PostgreSQL94Platform.php +++ b/src/Platforms/PostgreSQL94Platform.php @@ -170,24 +170,6 @@ public function getListDatabasesSQL(): string return 'SELECT datname FROM pg_database'; } - /** - * @deprecated Use {@link PostgreSQLSchemaManager::listSchemaNames()} instead. - */ - public function getListNamespacesSQL(): string - { - Deprecation::triggerIfCalledFromOutside( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/issues/4503', - 'PostgreSQL94Platform::getListNamespacesSQL() is deprecated,' - . ' use PostgreSQLSchemaManager::listSchemaNames() instead.' - ); - - return "SELECT schema_name AS nspname - FROM information_schema.schemata - WHERE schema_name NOT LIKE 'pg\_%' - AND schema_name != 'information_schema'"; - } - public function getListSequencesSQL(string $database): string { return "SELECT sequence_name AS relname, diff --git a/src/Platforms/SQLServer2012Platform.php b/src/Platforms/SQLServer2012Platform.php index 4325d14c45a..22fcda1b9d3 100644 --- a/src/Platforms/SQLServer2012Platform.php +++ b/src/Platforms/SQLServer2012Platform.php @@ -1050,21 +1050,6 @@ public function getListDatabasesSQL(): string return 'SELECT * FROM sys.databases'; } - /** - * @deprecated Use {@link SQLServerSchemaManager::listSchemaNames()} instead. - */ - public function getListNamespacesSQL(): string - { - Deprecation::triggerIfCalledFromOutside( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/issues/4503', - 'SQLServer2012Platform::getListNamespacesSQL() is deprecated,' - . ' use SQLServerSchemaManager::listSchemaNames() instead.' - ); - - return "SELECT name FROM sys.schemas WHERE name NOT IN('guest', 'INFORMATION_SCHEMA', 'sys')"; - } - public function getSubstringExpression(string $string, string $start, ?string $length = null): string { if ($length === null) { diff --git a/src/Schema/AbstractSchemaManager.php b/src/Schema/AbstractSchemaManager.php index 55309a96c90..ac194b2241e 100644 --- a/src/Schema/AbstractSchemaManager.php +++ b/src/Schema/AbstractSchemaManager.php @@ -12,7 +12,6 @@ use Doctrine\DBAL\Exception\DatabaseRequired; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\Exception\NotSupported; -use Doctrine\Deprecations\Deprecation; use Throwable; use function array_filter; @@ -98,31 +97,6 @@ public function listDatabases(): array return $this->_getPortableDatabasesList($databases); } - /** - * Returns a list of all namespaces in the current database. - * - * @deprecated Use {@link listSchemaNames()} instead. - * - * @return array - * - * @throws Exception - */ - public function listNamespaceNames(): array - { - Deprecation::triggerIfCalledFromOutside( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/issues/4503', - 'AbstractSchemaManager::listNamespaceNames() is deprecated,' - . ' use AbstractSchemaManager::listSchemaNames() instead.' - ); - - $sql = $this->_platform->getListNamespacesSQL(); - - $namespaces = $this->_conn->fetchAllAssociative($sql); - - return $this->getPortableNamespacesList($namespaces); - } - /** * Returns a list of the names of all schemata in the current database. * @@ -643,34 +617,6 @@ protected function _getPortableDatabasesList(array $databases): array return $list; } - /** - * Converts a list of namespace names from the native DBMS data definition to a portable Doctrine definition. - * - * @deprecated Use {@link listSchemaNames()} instead. - * - * @param array> $namespaces The list of namespace names - * in the native DBMS data definition. - * - * @return array - */ - protected function getPortableNamespacesList(array $namespaces): array - { - Deprecation::triggerIfCalledFromOutside( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/issues/4503', - 'AbstractSchemaManager::getPortableNamespacesList() is deprecated,' - . ' use AbstractSchemaManager::listSchemaNames() instead.' - ); - - $namespacesList = []; - - foreach ($namespaces as $namespace) { - $namespacesList[] = $this->getPortableNamespaceDefinition($namespace); - } - - return $namespacesList; - } - /** * @param array $database */ @@ -681,18 +627,6 @@ protected function _getPortableDatabaseDefinition(array $database): string return array_shift($database); } - /** - * Converts a namespace definition from the native DBMS data definition to a portable Doctrine definition. - * - * @deprecated Use {@link listSchemaNames()} instead. - * - * @param array $namespace The native DBMS namespace definition. - */ - protected function getPortableNamespaceDefinition(array $namespace): string - { - return array_shift($namespace); - } - /** * @param array> $sequences * @@ -973,7 +907,7 @@ public function createSchema(): Schema $schemaNames = []; if ($this->_platform->supportsSchemas()) { - $schemaNames = $this->listNamespaceNames(); + $schemaNames = $this->listSchemaNames(); } $sequences = []; diff --git a/src/Schema/PostgreSQLSchemaManager.php b/src/Schema/PostgreSQLSchemaManager.php index aea82b64eb9..4ad57a49102 100644 --- a/src/Schema/PostgreSQLSchemaManager.php +++ b/src/Schema/PostgreSQLSchemaManager.php @@ -4,11 +4,9 @@ namespace Doctrine\DBAL\Schema; -use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; -use Doctrine\Deprecations\Deprecation; use function array_change_key_case; use function array_filter; @@ -37,27 +35,6 @@ class PostgreSQLSchemaManager extends AbstractSchemaManager /** @var array|null */ private $existingSchemaPaths; - /** - * Gets all the existing schema names. - * - * @deprecated Use {@link listSchemaNames()} instead. - * - * @return array - * - * @throws Exception - */ - public function getSchemaNames(): array - { - Deprecation::trigger( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/issues/4503', - 'PostgreSQLSchemaManager::getSchemaNames() is deprecated,' - . ' use PostgreSQLSchemaManager::listSchemaNames() instead.' - ); - - return $this->listNamespaceNames(); - } - /** * {@inheritDoc} */ @@ -97,11 +74,9 @@ public function getSchemaSearchPaths(): array * * This is a PostgreSQL only function. * - * @internal The method should be only used from within the PostgreSQLSchemaManager class hierarchy. - * * @return array */ - public function getExistingSchemaSearchPaths(): array + protected function getExistingSchemaSearchPaths(): array { if ($this->existingSchemaPaths === null) { $this->determineExistingSchemaSearchPaths(); @@ -114,10 +89,8 @@ public function getExistingSchemaSearchPaths(): array * Sets or resets the order of the existing schemas in the current search path of the user. * * This is a PostgreSQL only function. - * - * @internal The method should be only used from within the PostgreSQLSchemaManager class hierarchy. */ - public function determineExistingSchemaSearchPaths(): void + protected function determineExistingSchemaSearchPaths(): void { $names = $this->listSchemaNames(); $paths = $this->getSchemaSearchPaths(); @@ -283,23 +256,6 @@ protected function _getPortableSequencesList(array $sequences): array return $list; } - /** - * {@inheritdoc} - * - * @deprecated Use {@link listSchemaNames()} instead. - */ - protected function getPortableNamespaceDefinition(array $namespace): string - { - Deprecation::triggerIfCalledFromOutside( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/issues/4503', - 'PostgreSQLSchemaManager::getPortableNamespaceDefinition() is deprecated,' - . ' use PostgreSQLSchemaManager::listSchemaNames() instead.' - ); - - return $namespace['nspname']; - } - /** * {@inheritdoc} */ diff --git a/src/Schema/SQLServerSchemaManager.php b/src/Schema/SQLServerSchemaManager.php index 00a225b71a6..58185262aac 100644 --- a/src/Schema/SQLServerSchemaManager.php +++ b/src/Schema/SQLServerSchemaManager.php @@ -7,7 +7,6 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Types\Type; -use Doctrine\Deprecations\Deprecation; use PDOException; use function assert; @@ -226,23 +225,6 @@ protected function _getPortableDatabaseDefinition(array $database): string return $database['name']; } - /** - * {@inheritdoc} - * - * @deprecated Use {@link listSchemaNames()} instead. - */ - protected function getPortableNamespaceDefinition(array $namespace): string - { - Deprecation::triggerIfCalledFromOutside( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/issues/4503', - 'SQLServerSchemaManager::getPortableNamespaceDefinition() is deprecated,' - . ' use SQLServerSchemaManager::listSchemaNames() instead.' - ); - - return $namespace['name']; - } - /** * {@inheritdoc} */ diff --git a/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php b/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php index dfa051ef4a0..b3a8cae5a5b 100644 --- a/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php +++ b/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php @@ -9,7 +9,6 @@ use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\ForeignKeyConstraint; -use Doctrine\DBAL\Schema\PostgreSQLSchemaManager; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\BlobType; @@ -20,7 +19,6 @@ use function array_map; use function array_pop; use function array_unshift; -use function assert; use function count; use function preg_match; use function strtolower; @@ -47,9 +45,7 @@ public function testGetSearchPath(): void public function testGetSchemaNames(): void { - assert($this->schemaManager instanceof PostgreSQLSchemaManager); - - $names = $this->schemaManager->getSchemaNames(); + $names = $this->schemaManager->listSchemaNames(); self::assertContains('public', $names, 'The public schema should be found.'); } diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index 15356814644..f332de445a8 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -154,10 +154,7 @@ public function testListDatabases(): void self::assertContains('test_create_database', $databases); } - /** - * @dataProvider listSchemaNamesMethodProvider - */ - public function testListSchemaNames(callable $method): void + public function testListSchemaNames(): void { if (! $this->schemaManager->getDatabasePlatform()->supportsSchemas()) { self::markTestSkipped('Platform does not support schemas.'); @@ -169,25 +166,7 @@ public function testListSchemaNames(callable $method): void $this->schemaManager->getDatabasePlatform()->getCreateSchemaSQL('test_create_schema') ); - self::assertContains('test_create_schema', $method($this->schemaManager)); - } - - /** - * @return iterable> - */ - public static function listSchemaNamesMethodProvider(): iterable - { - yield [ - static function (AbstractSchemaManager $schemaManager): array { - return $schemaManager->listNamespaceNames(); - }, - ]; - - yield [ - static function (AbstractSchemaManager $schemaManager): array { - return $schemaManager->listSchemaNames(); - }, - ]; + self::assertContains('test_create_schema', $this->schemaManager->listSchemaNames()); } public function testListTables(): void