Skip to content

Remove the APIs deprecated in DBAL 3.x #5423

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

Merged
merged 5 commits into from
Jun 2, 2022
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
23 changes: 23 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,29 @@ awareness about deprecated code.

# Upgrade to 4.0

## BC BREAK: foreign key DDL is generated on MySQL regardless of the storage engine.

The DBAL generates DDL for foreign keys regardless of the MySQL storage engines used by the table
that owns the foreign key constraint.

## BC BREAK: removed `AbstractPlatform` methods exposing quote characters.

The `AbstractPlatform::getStringLiteralQuoteCharacter()` and `::getIdentifierQuoteCharacter()` methods
have been removed.

## Deprecated: `AbstractPlatform::CREATE_*` constants

The `AbstractPlatform::CREATE_INDEXES` and `::CREATE_FOREIGNKEYS` constants have been deprecated
as they no longer have any effect on the behavior of the `AbstractPlatform::getCreateTableSQL()` method.

## BC BREAK: removed `$createFlags` from `AbstractPlatform::getCreateTableSQL()`

The `$createFlags` parameter of `AbstractPlatform::getCreateTableSQL()` has been removed.

## BC BREAK: removed `CreateSchemaSqlCollector` and `DropSchemaSqlCollector`

The `CreateSchemaSqlCollector` and `DropSchemaSqlCollector` classes have been removed.

## BC BREAK: remove support for transaction nesting without savepoints

Starting a transaction inside another transaction with
Expand Down
15 changes: 0 additions & 15 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@
<file name="src/Driver/OCI8/ConvertPositionalToNamedPlaceholders.php"/>
</errorLevel>
</ConflictingReferenceConstraint>
<DeprecatedClass>
<errorLevel type="suppress">
<!--
TODO: remove in 4.0.0
-->
<referencedClass name="Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector"/>
<referencedClass name="Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector"/>
</errorLevel>
</DeprecatedClass>
<DeprecatedMethod>
<errorLevel type="suppress">
<!--
Expand All @@ -63,12 +54,6 @@
<!--
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractMySQLPlatform::getIdentifierQuoteCharacter"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getIdentifierQuoteCharacter"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getStringLiteralQuoteCharacter"/>
<!--
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::supportsForeignKeyConstraints"/>
</errorLevel>
</DeprecatedMethod>
Expand Down
68 changes: 6 additions & 62 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\Deprecations\Deprecation;

use function array_merge;
use function array_unique;
Expand All @@ -24,7 +23,6 @@
use function is_numeric;
use function sprintf;
use function str_replace;
use function strcasecmp;
use function strtoupper;
use function trim;

Expand Down Expand Up @@ -57,18 +55,9 @@ protected function doModifyLimitQuery(string $query, ?int $limit, int $offset):
return $query;
}

/**
* @deprecated Use {@see quoteIdentifier()} to quote identifiers instead.
*/
public function getIdentifierQuoteCharacter(): string
public function quoteSingleIdentifier(string $str): string
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5388',
'AbstractMySQLPlatform::getIdentifierQuoteCharacter() is deprecated. Use quoteIdentifier() instead.'
);

return '`';
return '`' . str_replace('`', '``', $str) . '`';
}

public function getRegexpExpression(): string
Expand Down Expand Up @@ -220,38 +209,6 @@ public function getListTablesSQL(): string
return "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'";
}

/**
* {@inheritDoc}
*/
public function getCreateTablesSQL(array $tables): array
{
$sql = [];

foreach ($tables as $table) {
$sql = array_merge($sql, $this->getCreateTableWithoutForeignKeysSQL($table));
}

foreach ($tables as $table) {
if (! $table->hasOption('engine') || $this->engineSupportsForeignKeys($table->getOption('engine'))) {
foreach ($table->getForeignKeys() as $foreignKey) {
$sql[] = $this->getCreateForeignKeySQL(
$foreignKey,
$table->getQuotedName($this)
);
}
} elseif (count($table->getForeignKeys()) > 0) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5414',
'Relying on the DBAL not generating DDL for foreign keys on MySQL engines'
. ' other than InnoDB is deprecated. Define foreign key constraints only if they are necessary.'
);
}
}

return $sql;
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -300,17 +257,8 @@ protected function _getCreateTableSQL(string $name, array $columns, array $optio

// Propagate foreign key constraints only for InnoDB.
if (isset($options['foreignKeys'])) {
if (! isset($options['engine']) || $this->engineSupportsForeignKeys($options['engine'])) {
foreach ($options['foreignKeys'] as $definition) {
$sql[] = $this->getCreateForeignKeySQL($definition, $name);
}
} elseif (count($options['foreignKeys']) > 0) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5414',
'Relying on the DBAL not generating DDL for foreign keys on MySQL engines'
. ' other than InnoDB is deprecated. Define foreign key constraints only if they are necessary.'
);
foreach ($options['foreignKeys'] as $definition) {
$sql[] = $this->getCreateForeignKeySQL($definition, $name);
}
}

Expand Down Expand Up @@ -360,11 +308,6 @@ private function buildTableOptions(array $options): string
return implode(' ', $tableOptions);
}

private function engineSupportsForeignKeys(string $engine): bool
{
return strcasecmp(trim($engine), 'InnoDB') === 0;
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -820,7 +763,8 @@ public function getBlobTypeDeclarationSQL(array $column): string

public function quoteStringLiteral(string $str): string
{
$str = str_replace('\\', '\\\\', $str); // MySQL requires backslashes to be escaped aswell.
// MySQL requires backslashes to be escaped as well.
$str = str_replace('\\', '\\\\', $str);

return parent::quoteStringLiteral($str);
}
Expand Down
102 changes: 22 additions & 80 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use Doctrine\DBAL\Types;
use Doctrine\DBAL\Types\Exception\TypeNotFound;
use Doctrine\DBAL\Types\Type;
use Doctrine\Deprecations\Deprecation;
use InvalidArgumentException;
use UnexpectedValueException;

Expand Down Expand Up @@ -72,8 +71,14 @@
*/
abstract class AbstractPlatform
{
/**
* @deprecated
*/
public const CREATE_INDEXES = 1;

/**
* @deprecated
*/
public const CREATE_FOREIGNKEYS = 2;

/** @var string[]|null */
Expand Down Expand Up @@ -376,22 +381,6 @@ public function hasDoctrineTypeMappingFor(string $dbType): bool
return isset($this->doctrineTypeMapping[$dbType]);
}

/**
* Gets the character used for identifier quoting.
*
* @deprecated Use {@see quoteIdentifier()} to quote identifiers instead.
*/
public function getIdentifierQuoteCharacter(): string
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5388',
'AbstractPlatform::getIdentifierQuoteCharacter() is deprecated. Use quoteIdentifier() instead.'
);

return '"';
}

/**
* Returns the regular expression operator.
*
Expand Down Expand Up @@ -871,37 +860,13 @@ public function getDropUniqueConstraintSQL(string $name, string $tableName): str
* Returns the SQL statement(s) to create a table with the specified name, columns and constraints
* on this platform.
*
* @psalm-param int-mask-of<self::CREATE_*> $createFlags
*
* @return list<string> The list of SQL statements.
*
* @throws Exception
*/
public function getCreateTableSQL(Table $table, int $createFlags = self::CREATE_INDEXES): array
public function getCreateTableSQL(Table $table): array
{
if (($createFlags & self::CREATE_INDEXES) === 0) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5416',
'Unsetting the CREATE_INDEXES flag in AbstractPlatform::getCreateTableSQL() is deprecated.'
);
}

if (($createFlags & self::CREATE_FOREIGNKEYS) === 0) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5416',
'Not setting the CREATE_FOREIGNKEYS flag in AbstractPlatform::getCreateTableSQL()'
. ' is deprecated. In order to build the statements that create multiple tables'
. ' referencing each other via foreign keys, use AbstractPlatform::getCreateTablesSQL().'
);
}

return $this->buildCreateTableSQL(
$table,
($createFlags & self::CREATE_INDEXES) > 0,
($createFlags & self::CREATE_FOREIGNKEYS) > 0
);
return $this->buildCreateTableSQL($table, true);
}

/**
Expand All @@ -913,15 +878,15 @@ public function getCreateTableSQL(Table $table, int $createFlags = self::CREATE_
*/
final protected function getCreateTableWithoutForeignKeysSQL(Table $table): array
{
return $this->buildCreateTableSQL($table, true, false);
return $this->buildCreateTableSQL($table, false);
}

/**
* @return list<string>
*
* @throws Exception
*/
private function buildCreateTableSQL(Table $table, bool $createIndexes, bool $createForeignKeys): array
private function buildCreateTableSQL(Table $table, bool $createForeignKeys): array
{
if (count($table->getColumns()) === 0) {
throw NoColumnsSpecifiedForTable::new($table->getName());
Expand All @@ -933,21 +898,19 @@ private function buildCreateTableSQL(Table $table, bool $createIndexes, bool $cr
$options['indexes'] = [];
$options['primary'] = [];

if ($createIndexes) {
foreach ($table->getIndexes() as $index) {
if (! $index->isPrimary()) {
$options['indexes'][$index->getQuotedName($this)] = $index;

continue;
}
foreach ($table->getIndexes() as $index) {
if (! $index->isPrimary()) {
$options['indexes'][$index->getQuotedName($this)] = $index;

$options['primary'] = $index->getQuotedColumns($this);
$options['primary_index'] = $index;
continue;
}

foreach ($table->getUniqueConstraints() as $uniqueConstraint) {
$options['uniqueConstraints'][$uniqueConstraint->getQuotedName($this)] = $uniqueConstraint;
}
$options['primary'] = $index->getQuotedColumns($this);
$options['primary_index'] = $index;
}

foreach ($table->getUniqueConstraints() as $uniqueConstraint) {
$options['uniqueConstraints'][$uniqueConstraint->getQuotedName($this)] = $uniqueConstraint;
}

if ($createForeignKeys) {
Expand Down Expand Up @@ -1316,9 +1279,7 @@ public function quoteIdentifier(string $identifier): string
*/
public function quoteSingleIdentifier(string $str): string
{
$c = $this->getIdentifierQuoteCharacter();

return $c . str_replace($c, $c . $c, $str) . $c;
return '"' . str_replace('"', '""', $str) . '"';
}

/**
Expand Down Expand Up @@ -2531,26 +2492,7 @@ abstract protected function createReservedKeywordsList(): KeywordList;
*/
public function quoteStringLiteral(string $str): string
{
$c = $this->getStringLiteralQuoteCharacter();

return $c . str_replace($c, $c . $c, $str) . $c;
}

/**
* Gets the character used for string literal quoting.
*
* @deprecated Use {@see quoteStringLiteral()} to quote string literals instead.
*/
public function getStringLiteralQuoteCharacter(): string
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5388',
'AbstractPlatform::getStringLiteralQuoteCharacter() is deprecated.'
. ' Use quoteStringLiteral() instead.'
);

return "'";
return "'" . str_replace("'", "''", $str) . "'";
}

/**
Expand Down
10 changes: 0 additions & 10 deletions src/Platforms/SqlitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,16 +628,6 @@ public function getDropForeignKeySQL(string $foreignKey, string $table): string
throw new Exception('Sqlite platform does not support alter foreign key.');
}

/**
* {@inheritDoc}
*/
public function getCreateTableSQL(
Table $table,
int $createFlags = self::CREATE_INDEXES | self::CREATE_FOREIGNKEYS
): array {
return parent::getCreateTableSQL($table, $createFlags);
}

/**
* {@inheritDoc}
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,7 @@ public function createDatabase(string $database): void
*/
public function createTable(Table $table): void
{
$createFlags = AbstractPlatform::CREATE_INDEXES | AbstractPlatform::CREATE_FOREIGNKEYS;
$this->_execSql($this->_platform->getCreateTableSQL($table, $createFlags));
$this->_execSql($this->_platform->getCreateTableSQL($table));
}

/**
Expand Down
Loading