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

Add missing schema name on drop index statement on psql #6244

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/Platforms/PostgreSQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,28 @@
return $this->getDropConstraintSQL($constraintName, $table);
}

return parent::getDropIndexSQL($index, $table);
if ($index instanceof Index) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4798',
'Passing $index as an Index object to %s is deprecated. Pass it as a quoted name instead.',
__METHOD__,
);

Check warning on line 837 in src/Platforms/PostgreSQLPlatform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/PostgreSQLPlatform.php#L832-L837

Added lines #L832 - L837 were not covered by tests

$index = $index->getQuotedName($this);

Check warning on line 839 in src/Platforms/PostgreSQLPlatform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/PostgreSQLPlatform.php#L839

Added line #L839 was not covered by tests
} elseif (! is_string($index)) {
throw new InvalidArgumentException(

Check failure on line 841 in src/Platforms/PostgreSQLPlatform.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2)

Instantiated class Doctrine\DBAL\Platforms\InvalidArgumentException not found.

Check failure on line 841 in src/Platforms/PostgreSQLPlatform.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2)

Throwing object of an unknown class Doctrine\DBAL\Platforms\InvalidArgumentException.
__METHOD__ . '() expects $index parameter to be string or ' . Index::class . '.',
);

Check warning on line 843 in src/Platforms/PostgreSQLPlatform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/PostgreSQLPlatform.php#L841-L843

Added lines #L841 - L843 were not covered by tests
}

if (strpos($table, '.') !== false) {

Check failure on line 846 in src/Platforms/PostgreSQLPlatform.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2)

Parameter #1 $haystack of function strpos expects string, Doctrine\DBAL\Schema\Table|string|null given.

Check failure on line 846 in src/Platforms/PostgreSQLPlatform.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Expected 1 line after "if", found 2.
[$schema] = explode('.', $table);

Check failure on line 847 in src/Platforms/PostgreSQLPlatform.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2)

Parameter #2 $string of function explode expects string, Doctrine\DBAL\Schema\Table|string|null given.
$index = $schema . '.' . $index;
}

Check failure on line 850 in src/Platforms/PostgreSQLPlatform.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Functions must not contain multiple empty lines in a row; found 2 empty lines

return 'DROP INDEX ' . $index;

Check failure on line 852 in src/Platforms/PostgreSQLPlatform.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Expected 1 line before "return", found 2.
}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/Platforms/PostgreSQLPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1069,4 +1069,12 @@ public function testInitializesJsonTypeMapping(): void
self::assertTrue($this->platform->hasDoctrineTypeMappingFor('jsonb'));
self::assertEquals(Types::JSON, $this->platform->getDoctrineTypeMapping('jsonb'));
}

public function testDropIndexSQLRequiresTable(): void
{
self::assertSame(
'DROP INDEX schema.idx_id',
$this->platform->getDropIndexSQL('idx_id', 'schema.table'),
);
}
}