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

Fix incorrect syntax for dropping primary indexes in PostgreSQL #6025

Merged
merged 17 commits into from
Jun 15, 2023

Conversation

f-lombardo
Copy link
Contributor

@f-lombardo f-lombardo commented Apr 30, 2023

Q A
Type bug/feature/improvement
Fixed issues #6024

Summary

The correct way of dropping primary index in PostgreSQL is not dropping the index, but removing the primary key constraints

tests/Platforms/PostgreSQLPlatformTest.php Outdated Show resolved Hide resolved
src/Platforms/PostgreSQLPlatform.php Outdated Show resolved Hide resolved
@derrabus
Copy link
Member

derrabus commented May 1, 2023

Please add a functional test that reproduces your problem. Your test makes assertions on the produced SQL statements, but that neither tells me that the new statement is correct nor that the old one is incorrect.

@f-lombardo
Copy link
Contributor Author

f-lombardo commented May 1, 2023

Please add a functional test that reproduces your problem. Your test makes assertions on the produced SQL statements, but that neither tells me that the new statement is correct nor that the old one is incorrect.

Yes, it would be a good thing to add a functional test. Could you please give me a pointer to the process of creating a new functional test?

@derrabus
Copy link
Member

derrabus commented May 2, 2023

Have a look at any test in the tests/Functional directory.

@f-lombardo
Copy link
Contributor Author

Have a look at any test in the tests/Functional directory.

I've already seen them and they seems simple to replicate. My problem is that I don't know exactly how to run them against PostgreSQL.

Thanks in advance.

@derrabus
Copy link
Member

derrabus commented May 2, 2023

You'll find a PHPUnit configuration in ci/github/phpunit/pgsql.xml. Prepare a local Postgres server with an empty database and adjust the settings in ci/github/phpunit/pgsql.xml to match your environment.

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. We're almost there, I think. 🙂

tests/Functional/Driver/PDO/PgSQL/DBAL6024Test.php Outdated Show resolved Hide resolved
tests/Functional/Driver/PDO/PgSQL/DBAL6024Test.php Outdated Show resolved Hide resolved
@derrabus
Copy link
Member

You can run vendor/bin/phpcbf to fix the issues reported by PHPCS. And please have a look at the errors reported by PHPStan. They're valid as far as I can tell.

Copy link
Member

@derrabus derrabus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your new test apparently only works on MySQL and Postgres. That's a problem that we can solve in a follow-up PR. Please skip the test for all failing platforms. Sorry for the back and forth here. 🙈

tests/Functional/Driver/PDO/PgSQL/DBAL6024Test.php Outdated Show resolved Hide resolved
@f-lombardo
Copy link
Contributor Author

Your new test apparently only works on MySQL and Postgres. That's a problem that we can solve in a follow-up PR. Please skip the test for all failing platforms. Sorry for the back and forth here. 🙈

Uhm, I think it would be better to revert to the initial code that was designed just for PostgreSQL, since the fix is actually realated to a problem with this DB. What do you think?

Co-authored-by: Alexander M. Turek <me@derrabus.de>
Comment on lines 818 to 819
/** @psalm-suppress MissingClosureParamType */
$tableName = static fn ($t): string => $t instanceof Table ? $t->getName() : (string) $t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this a private method. This allows us to document the parameter type via PHPDoc which should make Psalm happy.

@derrabus derrabus merged commit 19f0dec into doctrine:3.6.x Jun 15, 2023
derrabus added a commit to derrabus/dbal that referenced this pull request Jun 15, 2023
* 3.6.x:
  Fix incorrect syntax for dropping primary indexes in PostgreSQL (doctrine#6025)
  trigger if called outside for AbstractPlatform::supportsCreateDropDatabase (doctrine#6064)
  Run tests with PHP 8.3 (doctrine#6060)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants