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 all commits
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 @@ -16,6 +16,7 @@
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\Types;
use Doctrine\Deprecations\Deprecation;
use InvalidArgumentException;
use UnexpectedValueException;

use function array_diff;
Expand Down Expand Up @@ -828,7 +829,27 @@
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 838 in src/Platforms/PostgreSQLPlatform.php

View check run for this annotation

Codecov / codecov/patch

src/Platforms/PostgreSQLPlatform.php#L833-L838

Added lines #L833 - L838 were not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

src/Platforms/PostgreSQLPlatform.php#L840

Added line #L840 was not covered by tests
} elseif (! is_string($index)) {
throw new InvalidArgumentException(
__METHOD__ . '() expects $index parameter to be string or ' . Index::class . '.',
);

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

View check run for this annotation

Codecov / codecov/patch

src/Platforms/PostgreSQLPlatform.php#L842-L844

Added lines #L842 - L844 were not covered by tests
}

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

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 #1 $haystack of function strpos expects string, Doctrine\DBAL\Schema\Table|string|null given.
[$schema] = explode('.', $table);

Check failure on line 848 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;
}

return 'DROP INDEX ' . $index;
}

/**
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'),
);
}
}