Skip to content

Commit

Permalink
Merge pull request #5387 from morozov/deprecate-schema-manager-get-pl…
Browse files Browse the repository at this point in the history
…atform

Deprecate AbstractSchemaManager::getDatabasePlatform()
  • Loading branch information
morozov authored May 12, 2022
2 parents 2deb141 + f3096df commit 7d3351b
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 37 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ awareness about deprecated code.

# Upgrade to 3.4

## Deprecated `AbstractSchemaManager::getDatabasePlatform()`

The `AbstractSchemaManager::getDatabasePlatform()` method has been deprecated. Use `Connection::getDatabasePlatform()`
instead.

## Deprecated passing date interval parameters as integer.

Passing date interval parameters to the following `AbstractPlatform` methods as integer has been deprecated:
Expand Down
11 changes: 10 additions & 1 deletion src/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,19 @@ public function __construct(Connection $connection, AbstractPlatform $platform)
/**
* Returns the associated platform.
*
* @deprecated Use {@link Connection::getDatabasePlatform()} instead.
*
* @return T
*/
public function getDatabasePlatform()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5387',
'AbstractSchemaManager::getDatabasePlatform() is deprecated.'
. ' Use Connection::getDatabasePlatform() instead.'
);

return $this->_platform;
}

Expand Down Expand Up @@ -1551,7 +1560,7 @@ private function getDatabase(string $methodName): string

public function createComparator(): Comparator
{
return new Comparator($this->getDatabasePlatform());
return new Comparator($this->_platform);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/MySQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys)

public function createComparator(): Comparator
{
return new MySQL\Comparator($this->getDatabasePlatform());
return new MySQL\Comparator($this->_platform);
}

protected function selectDatabaseColumns(string $databaseName, ?string $tableName = null): Result
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/SQLServerSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ private function getColumnConstraints(string $table, string $column): iterable
*/
public function createComparator(): Comparator
{
return new SQLServer\Comparator($this->getDatabasePlatform(), $this->getDatabaseCollation());
return new SQLServer\Comparator($this->_platform, $this->getDatabaseCollation());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/SqliteSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ private function getCreateTableSQL(string $table): string

public function createComparator(): Comparator
{
return new SQLite\Comparator($this->getDatabasePlatform());
return new SQLite\Comparator($this->_platform);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions tests/Functional/Schema/MySQLSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function testDropPrimaryKeyWithAutoincrementColumn(): void

public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes(): void
{
if ($this->schemaManager->getDatabasePlatform() instanceof MariaDb1027Platform) {
if ($this->connection->getDatabasePlatform() instanceof MariaDb1027Platform) {
self::markTestSkipped(
'MariaDb102Platform supports default values for BLOB and TEXT columns and will propagate values'
);
Expand Down Expand Up @@ -303,7 +303,7 @@ public function testListLobTypeColumns(): void

$this->dropAndCreateTable($table);

$platform = $this->schemaManager->getDatabasePlatform();
$platform = $this->connection->getDatabasePlatform();
$offlineColumns = $table->getColumns();
$onlineColumns = $this->schemaManager->listTableColumns($tableName);

Expand Down Expand Up @@ -406,7 +406,7 @@ public function testJsonColumnType(): void

public function testColumnDefaultCurrentTimestamp(): void
{
$platform = $this->schemaManager->getDatabasePlatform();
$platform = $this->connection->getDatabasePlatform();

$table = new Table('test_column_defaults_current_timestamp');

Expand All @@ -429,7 +429,7 @@ public function testColumnDefaultsAreValid(): void
{
$table = new Table('test_column_defaults_are_valid');

$currentTimeStampSql = $this->schemaManager->getDatabasePlatform()->getCurrentTimestampSQL();
$currentTimeStampSql = $this->connection->getDatabasePlatform()->getCurrentTimestampSQL();
$table->addColumn('col_datetime', 'datetime', ['default' => $currentTimeStampSql]);
$table->addColumn('col_datetime_null', 'datetime', ['notnull' => false, 'default' => null]);
$table->addColumn('col_int', 'integer', ['default' => 1]);
Expand Down Expand Up @@ -471,11 +471,11 @@ public function testColumnDefaultsAreValid(): void
*/
public function testColumnDefaultValuesCurrentTimeAndDate(): void
{
if (! $this->schemaManager->getDatabasePlatform() instanceof MariaDb1027Platform) {
if (! $this->connection->getDatabasePlatform() instanceof MariaDb1027Platform) {
self::markTestSkipped('Only relevant for MariaDb102Platform.');
}

$platform = $this->schemaManager->getDatabasePlatform();
$platform = $this->connection->getDatabasePlatform();

$table = new Table('test_column_defaults_current_time_and_date');

Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Schema/OracleSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements()
$onlinePrimaryTable = $this->schemaManager->listTableDetails($primaryTableName);
$onlineForeignTable = $this->schemaManager->listTableDetails($foreignTableName);

$platform = $this->schemaManager->getDatabasePlatform();
$platform = $this->connection->getDatabasePlatform();

// Primary table assertions
self::assertSame($primaryTableName, $onlinePrimaryTable->getQuotedName($platform));
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Schema/PostgreSQLSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function testAlterTableAutoIncrementAdd(callable $comparatorFactory): voi
$column = $tableTo->addColumn('id', 'integer');
$column->setAutoincrement(true);

$platform = $this->schemaManager->getDatabasePlatform();
$platform = $this->connection->getDatabasePlatform();
$diff = $comparatorFactory($this->schemaManager)->diffTable($tableFrom, $tableTo);
self::assertNotFalse($diff);

Expand Down Expand Up @@ -143,7 +143,7 @@ public function testAlterTableAutoIncrementDrop(callable $comparatorFactory): vo
$tableTo = new Table('autoinc_table_drop');
$tableTo->addColumn('id', 'integer');

$platform = $this->schemaManager->getDatabasePlatform();
$platform = $this->connection->getDatabasePlatform();
$diff = $comparatorFactory($this->schemaManager)->diffTable($tableFrom, $tableTo);
self::assertNotFalse($diff);

Expand Down
46 changes: 23 additions & 23 deletions tests/Functional/Schema/SchemaManagerFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function testListSequences(): void

public function testListDatabases(): void
{
if (! $this->schemaManager->getDatabasePlatform()->supportsCreateDropDatabase()) {
if (! $this->connection->getDatabasePlatform()->supportsCreateDropDatabase()) {
self::markTestSkipped('Cannot drop Database client side with this Driver.');
}

Expand Down Expand Up @@ -353,7 +353,7 @@ public function testListTableColumnsDispatchEvent(): void
$eventManager = new EventManager();
$eventManager->addEventListener([Events::onSchemaColumnDefinition], $listenerMock);

$this->schemaManager->getDatabasePlatform()->setEventManager($eventManager);
$this->connection->getDatabasePlatform()->setEventManager($eventManager);

$this->schemaManager->listTableColumns('list_table_columns');
}
Expand All @@ -374,7 +374,7 @@ public function testListTableIndexesDispatchEvent(): void
$eventManager = new EventManager();
$eventManager->addEventListener([Events::onSchemaIndexDefinition], $listenerMock);

$this->schemaManager->getDatabasePlatform()->setEventManager($eventManager);
$this->connection->getDatabasePlatform()->setEventManager($eventManager);

$this->schemaManager->listTableIndexes('list_table_indexes_test');
}
Expand Down Expand Up @@ -408,7 +408,7 @@ public function testDispatchEventWhenDatabasePlatformIsExplicitlyPassed(): void
*/
public function testDiffListTableColumns(callable $comparatorFactory): void
{
if ($this->schemaManager->getDatabasePlatform() instanceof OraclePlatform) {
if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
self::markTestSkipped(
'Does not work with Oracle, since it cannot detect DateTime, Date and Time differences (at the moment).'
);
Expand Down Expand Up @@ -498,7 +498,7 @@ public function testDropAndCreateUniqueConstraint(): void

public function testCreateTableWithForeignKeys(): void
{
if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) {
if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) {
self::markTestSkipped('Platform does not support foreign keys.');
}

Expand Down Expand Up @@ -602,7 +602,7 @@ public function testMigrateSchema(): void

public function testAlterTableScenario(): void
{
if (! $this->schemaManager->getDatabasePlatform()->supportsAlterTable()) {
if (! $this->connection->getDatabasePlatform()->supportsAlterTable()) {
self::markTestSkipped('Alter Table is not supported by this platform.');
}

Expand Down Expand Up @@ -683,7 +683,7 @@ public function testAlterTableScenario(): void
// dont check for index size here, some platforms automatically add indexes for foreign keys.
self::assertFalse($table->hasIndex('bar_idx'));

if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) {
if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) {
return;
}

Expand All @@ -697,15 +697,15 @@ public function testAlterTableScenario(): void

public function testTableInNamespace(): void
{
if (! $this->schemaManager->getDatabasePlatform()->supportsSchemas()) {
if (! $this->connection->getDatabasePlatform()->supportsSchemas()) {
self::markTestSkipped('Schema definition is not supported by this platform.');
}

//create schema
$diff = new SchemaDiff();
$diff->newNamespaces[] = 'testschema';

foreach ($diff->toSql($this->schemaManager->getDatabasePlatform()) as $sql) {
foreach ($diff->toSql($this->connection->getDatabasePlatform()) as $sql) {
$this->connection->executeStatement($sql);
}

Expand All @@ -721,7 +721,7 @@ public function testTableInNamespace(): void

public function testCreateAndListViews(): void
{
if (! $this->schemaManager->getDatabasePlatform()->supportsViews()) {
if (! $this->connection->getDatabasePlatform()->supportsViews()) {
self::markTestSkipped('Views is not supported by this platform.');
}

Expand All @@ -745,7 +745,7 @@ public function testCreateAndListViews(): void

public function testAutoincrementDetection(): void
{
if (! $this->schemaManager->getDatabasePlatform()->supportsIdentityColumns()) {
if (! $this->connection->getDatabasePlatform()->supportsIdentityColumns()) {
self::markTestSkipped('This test is only supported on platforms that have autoincrement');
}

Expand All @@ -763,7 +763,7 @@ public function testAutoincrementDetection(): void

public function testAutoincrementDetectionMulticolumns(): void
{
if (! $this->schemaManager->getDatabasePlatform()->supportsIdentityColumns()) {
if (! $this->connection->getDatabasePlatform()->supportsIdentityColumns()) {
self::markTestSkipped('This test is only supported on platforms that have autoincrement');
}

Expand All @@ -787,7 +787,7 @@ public function testAutoincrementDetectionMulticolumns(): void
*/
public function testUpdateSchemaWithForeignKeyRenaming(callable $comparatorFactory): void
{
$platform = $this->schemaManager->getDatabasePlatform();
$platform = $this->connection->getDatabasePlatform();

if (! $platform->supportsForeignKeyConstraints()) {
self::markTestSkipped('This test is only supported on platforms that have foreign keys.');
Expand Down Expand Up @@ -839,7 +839,7 @@ public function testUpdateSchemaWithForeignKeyRenaming(callable $comparatorFacto
*/
public function testRenameIndexUsedInForeignKeyConstraint(callable $comparatorFactory): void
{
$platform = $this->schemaManager->getDatabasePlatform();
$platform = $this->connection->getDatabasePlatform();

if (! $platform->supportsForeignKeyConstraints()) {
self::markTestSkipped('This test is only supported on platforms that have foreign keys.');
Expand Down Expand Up @@ -1207,11 +1207,11 @@ protected function assertVarBinaryColumnIsValid(Table $table, string $columnName

public function testListTableDetailsWithFullQualifiedTableName(): void
{
if (! $this->schemaManager->getDatabasePlatform()->supportsSchemas()) {
if (! $this->connection->getDatabasePlatform()->supportsSchemas()) {
self::markTestSkipped('Test only works on platforms that support schemas.');
}

$defaultSchemaName = $this->schemaManager->getDatabasePlatform()->getDefaultSchemaName();
$defaultSchemaName = $this->connection->getDatabasePlatform()->getDefaultSchemaName();
$primaryTableName = 'primary_table';
$foreignTableName = 'foreign_table';

Expand Down Expand Up @@ -1309,7 +1309,7 @@ public function testAlterColumnComment(
?string $comment2,
?string $expectedComment2
): void {
$platform = $this->schemaManager->getDatabasePlatform();
$platform = $this->connection->getDatabasePlatform();

if (
! $platform->supportsInlineColumnComments() &&
Expand Down Expand Up @@ -1381,7 +1381,7 @@ public static function getAlterColumnComment(): iterable

public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys(): void
{
if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) {
if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) {
self::markTestSkipped('This test is only supported on platforms that have foreign keys.');
}

Expand Down Expand Up @@ -1413,7 +1413,7 @@ public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys(): void
*/
public function testComparatorShouldNotAddCommentToJsonTypeSinceItIsTheDefaultNow(callable $comparatorFactory): void
{
$platform = $this->schemaManager->getDatabasePlatform();
$platform = $this->connection->getDatabasePlatform();

if (! $platform->hasNativeJsonType()) {
self::markTestSkipped('This test is only supported on platforms that have native JSON type.');
Expand Down Expand Up @@ -1460,7 +1460,7 @@ public function commentsProvider(): array

public function testCreateAndListSequences(): void
{
if (! $this->schemaManager->getDatabasePlatform()->supportsSequences()) {
if (! $this->connection->getDatabasePlatform()->supportsSequences()) {
self::markTestSkipped('This test is only supported on platforms that support sequences.');
}

Expand Down Expand Up @@ -1501,7 +1501,7 @@ public function testCreateAndListSequences(): void
*/
public function testComparisonWithAutoDetectedSequenceDefinition(callable $comparatorFactory): void
{
$platform = $this->schemaManager->getDatabasePlatform();
$platform = $this->connection->getDatabasePlatform();

if (! $platform->supportsSequences()) {
self::markTestSkipped('This test is only supported on platforms that support sequences.');
Expand Down Expand Up @@ -1562,7 +1562,7 @@ public function testPrimaryKeyAutoIncrement(): void

public function testGenerateAnIndexWithPartialColumnLength(): void
{
if (! $this->schemaManager->getDatabasePlatform()->supportsColumnLengthIndexes()) {
if (! $this->connection->getDatabasePlatform()->supportsColumnLengthIndexes()) {
self::markTestSkipped(
'This test is only supported on platforms that support indexes with column length definitions.'
);
Expand Down Expand Up @@ -1595,7 +1595,7 @@ public function testCommentInTable(): void

public function testCreatedCompositeForeignKeyOrderIsCorrectAfterCreation(): void
{
if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) {
if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) {
self::markTestSkipped('Platform does not support foreign keys.');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function dropTableIfExists(string $name): void
public function dropAndCreateTable(Table $table): void
{
$schemaManager = $this->connection->createSchemaManager();
$platform = $schemaManager->getDatabasePlatform();
$platform = $this->connection->getDatabasePlatform();
$tableName = $table->getQuotedName($platform);

$this->dropTableIfExists($tableName);
Expand Down

0 comments on commit 7d3351b

Please sign in to comment.