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

Remove $name from AbstractPlatform object declaration methods #4806

Merged
merged 1 commit into from
Sep 19, 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
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 4.0

## BC BREAK: Changed signatures of `AbstractPlatform::getIndexDeclarationSQL()` and `::getUniqueConstraintDeclarationSQL()`

The `AbstractPlatform::getIndexDeclarationSQL()` and `::getUniqueConstraintDeclarationSQL()` methods no longer accept
the name of the object as a separate parameter. The name of the passed index or constraint is used instead.

## BC BREAK: Removed `AbstractPlatform::canEmulateSchemas()`

The `AbstractPlatform::canEmulateSchemas()` method and the schema emulation implemented in the SQLite platform
Expand Down
21 changes: 9 additions & 12 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1130,8 +1130,8 @@ protected function _getCreateTableSQL(string $name, array $columns, array $optio
$columnListSql = $this->getColumnDeclarationListSQL($columns);

if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) {
foreach ($options['uniqueConstraints'] as $index => $definition) {
$columnListSql .= ', ' . $this->getUniqueConstraintDeclarationSQL($index, $definition);
foreach ($options['uniqueConstraints'] as $definition) {
$columnListSql .= ', ' . $this->getUniqueConstraintDeclarationSQL($definition);
}
}

Expand All @@ -1141,7 +1141,7 @@ protected function _getCreateTableSQL(string $name, array $columns, array $optio

if (isset($options['indexes']) && ! empty($options['indexes'])) {
foreach ($options['indexes'] as $index => $definition) {
$columnListSql .= ', ' . $this->getIndexDeclarationSQL($index, $definition);
$columnListSql .= ', ' . $this->getIndexDeclarationSQL($definition);
}
}

Expand Down Expand Up @@ -1747,14 +1747,13 @@ public function getCheckDeclarationSQL(array $definition): string
* Obtains DBMS specific SQL code portion needed to set a unique
* constraint declaration to be used in statements like CREATE TABLE.
*
* @param string $name The name of the unique constraint.
* @param UniqueConstraint $constraint The unique constraint definition.
*
* @return string DBMS specific SQL code portion needed to set a constraint.
*
* @throws InvalidArgumentException
*/
public function getUniqueConstraintDeclarationSQL(string $name, UniqueConstraint $constraint): string
public function getUniqueConstraintDeclarationSQL(UniqueConstraint $constraint): string
{
$columns = $constraint->getColumns();

Expand All @@ -1764,8 +1763,8 @@ public function getUniqueConstraintDeclarationSQL(string $name, UniqueConstraint

$chunks = ['CONSTRAINT'];

if ($name !== '') {
$chunks[] = (new Identifier($name))->getQuotedName($this);
if ($constraint->getName() !== '') {
$chunks[] = $constraint->getQuotedName($this);
}

$chunks[] = 'UNIQUE';
Expand All @@ -1783,23 +1782,21 @@ public function getUniqueConstraintDeclarationSQL(string $name, UniqueConstraint
* Obtains DBMS specific SQL code portion needed to set an index
* declaration to be used in statements like CREATE TABLE.
*
* @param string $name The name of the index.
* @param Index $index The index definition.
* @param Index $index The index definition.
*
* @return string DBMS specific SQL code portion needed to set an index.
*
* @throws InvalidArgumentException
*/
public function getIndexDeclarationSQL(string $name, Index $index): string
public function getIndexDeclarationSQL(Index $index): string
{
$columns = $index->getColumns();
$name = new Identifier($name);

if (count($columns) === 0) {
throw new InvalidArgumentException('Incomplete definition. "columns" required.');
}

return $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name->getQuotedName($this)
return $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $index->getQuotedName($this)
. ' (' . $this->getIndexFieldDeclarationListSQL($index) . ')' . $this->getPartialIndexSQL($index);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public function getCurrentTimestampSQL(): string
return 'CURRENT TIMESTAMP';
}

public function getIndexDeclarationSQL(string $name, Index $index): string
public function getIndexDeclarationSQL(Index $index): string
{
// Index declaration in statements like CREATE TABLE is not supported.
throw NotSupported::new(__METHOD__);
Expand Down
8 changes: 4 additions & 4 deletions src/Platforms/MySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,15 @@ protected function _getCreateTableSQL(string $name, array $columns, array $optio
$queryFields = $this->getColumnDeclarationListSQL($columns);

if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) {
foreach ($options['uniqueConstraints'] as $constraintName => $definition) {
$queryFields .= ', ' . $this->getUniqueConstraintDeclarationSQL($constraintName, $definition);
foreach ($options['uniqueConstraints'] as $definition) {
$queryFields .= ', ' . $this->getUniqueConstraintDeclarationSQL($definition);
}
}

// add all indexes
if (isset($options['indexes']) && ! empty($options['indexes'])) {
foreach ($options['indexes'] as $indexName => $definition) {
$queryFields .= ', ' . $this->getIndexDeclarationSQL($indexName, $definition);
foreach ($options['indexes'] as $definition) {
$queryFields .= ', ' . $this->getIndexDeclarationSQL($definition);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ protected function _getCreateTableSQL(string $name, array $columns, array $optio
$columnListSql = $this->getColumnDeclarationListSQL($columns);

if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) {
foreach ($options['uniqueConstraints'] as $constraintName => $definition) {
$columnListSql .= ', ' . $this->getUniqueConstraintDeclarationSQL($constraintName, $definition);
foreach ($options['uniqueConstraints'] as $definition) {
$columnListSql .= ', ' . $this->getUniqueConstraintDeclarationSQL($definition);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Platforms/SqlitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ protected function _getCreateTableSQL(string $name, array $columns, array $optio
$queryFields = $this->getColumnDeclarationListSQL($columns);

if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) {
foreach ($options['uniqueConstraints'] as $constraintName => $definition) {
$queryFields .= ', ' . $this->getUniqueConstraintDeclarationSQL($constraintName, $definition);
foreach ($options['uniqueConstraints'] as $definition) {
$queryFields .= ', ' . $this->getUniqueConstraintDeclarationSQL($definition);
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Platforms/AbstractPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ public function testGeneratesPartialIndexesSqlOnlyWhenSupportingPartialIndexes()
$indexes = [];

if ($this->supportsInlineIndexDeclaration()) {
$indexes[] = $this->platform->getIndexDeclarationSQL('name', $indexDef);
$indexes[] = $this->platform->getIndexDeclarationSQL($indexDef);
}

$uniqueConstraintSQL = $this->platform->getUniqueConstraintDeclarationSQL('name', $uniqueConstraint);
$uniqueConstraintSQL = $this->platform->getUniqueConstraintDeclarationSQL($uniqueConstraint);
self::assertStringEndsNotWith($expected, $uniqueConstraintSQL, 'WHERE clause should NOT be present');

$indexes[] = $this->platform->getCreateIndexSQL($indexDef, 'table');
Expand Down Expand Up @@ -722,7 +722,7 @@ public function testQuotesReservedKeywordInUniqueConstraintDeclarationSQL(): voi

self::assertSame(
$this->getQuotesReservedKeywordInUniqueConstraintDeclarationSQL(),
$this->platform->getUniqueConstraintDeclarationSQL('select', $constraint)
$this->platform->getUniqueConstraintDeclarationSQL($constraint)
);
}

Expand All @@ -748,7 +748,7 @@ public function testQuotesReservedKeywordInIndexDeclarationSQL(): void

self::assertSame(
$this->getQuotesReservedKeywordInIndexDeclarationSQL(),
$this->platform->getIndexDeclarationSQL('select', $index)
$this->platform->getIndexDeclarationSQL($index)
);
}

Expand Down