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

Make code compatible (and requiring) Doctrine ORM 2.10 and DBAL 3.0 #76

Merged
merged 4 commits into from
Jan 12, 2022

Conversation

piotaixr
Copy link
Contributor

@piotaixr piotaixr commented Nov 7, 2021

This PR updates the code and tests in order to be compatible with Doctrine ORM 2.10 and DBAL 3.0.
This PR contains breaking changes and should result in a new major version.
The implementation of the platform mocks is a dummy one and the strict minimum in order to have green tests.

A lot of imports that were not used are also cleaned.

The package.json file makes sure to require Doctrine ORM and DBAL as this libs depends on them.

Deprecations fixed:

  • Doctrine\DBAL\DBALException was renamed to Doctrine\DBAL\Exception
  • Doctrine\DBAL\Platforms\MySqlPlatform was renamed to Doctrine\DBAL\Platforms\MySQLPlatform
  • Doctrine\DBAL\Platforms\PostgreSqlPlatform does not exist anymore and is replaced by PostgreSql94Platform and PostgreSql100Platform.
  • Doctrine\DBAL\Connection#query now takes a string as parameter and returns a Result
  • Doctrine\DBAL\Connection#executeUpdate now returns an int. Making ConnectionMock#executeUpdate return 0 to have green tests
  • Doctrine\DBAL\Platforms\AbstractPlatform#prefersSequences does not exist anymore
  • The database platform mock must support an identity generator to have green tests. Making DatabasePlatformMock#supportsIdentityColumns return true.
  • Doctrine\DBAL\Driver has a new method: getExceptionConverter. Making the method throw in order to have the mock respect the interface and have green tests.
  • Doctrine\DBAL\Driver#getSchemaManager now takes the platform as second argument.

Closes #74

@mpiot
Copy link

mpiot commented Nov 18, 2021

I've just tested the branch in my project and it works well.
Thanks for the PR :)

@KornelKrupa
Copy link

Yes, it works well! You can merge.

@florentdestremau
Copy link

The fork is live in our project and works fine

@webmasterMeyers
Copy link

We are also using this for Postgres and it is working

@stephpy
Copy link

stephpy commented Nov 26, 2021

👍 I use it on sf 5.3, doctrine/dbal 3.1.4, doctrine/orm 2.10.2

@mpiot
Copy link

mpiot commented Jan 8, 2022

friendly ping @Hikariii

@Hikariii
Copy link
Member

Hikariii commented Jan 8, 2022

Thnx for the ping, I missed this somehow. I'll check, merge and release this next week.

@mpiot
Copy link

mpiot commented Jan 8, 2022

Thanks a lot @Hikariii

@Hikariii
Copy link
Member

Hikariii commented Jan 8, 2022

@piotaixr Because of the implemented requirements in the composer.json file this PR now has conflicts. Can you update this PR so the conflicts are resolved? If not I will make one myself.

@piotaixr
Copy link
Contributor Author

piotaixr commented Jan 8, 2022

I'll do it within the hour.

Copy link
Member

@Hikariii Hikariii left a comment

Choose a reason for hiding this comment

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

Just some minor comments. Thank you so much for your effort.

composer.json Outdated Show resolved Hide resolved
*/
protected function validatePlatform(SqlWalker$sqlWalker): void
{
if (!$sqlWalker->getConnection()->getDatabasePlatform() instanceof PostgreSqlPlatform) {
throw DBALException::notSupported(static::FUNCTION_NAME);
if (!$sqlWalker->getConnection()->getDatabasePlatform() instanceof PostgreSQL94Platform) {
Copy link
Member

Choose a reason for hiding this comment

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

Json functions are available from postgres 9.3 and this limits future versions of postgres.
I would steer clear from such specific details and just leave this as it was: PostgreSqlPlatform

Copy link
Contributor Author

@piotaixr piotaixr Jan 8, 2022

Choose a reason for hiding this comment

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

This platform does not exist anymore. The parent of PostgreSQL94Platform is now AbstractPlatform.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@Hikariii Hikariii Jan 8, 2022

Choose a reason for hiding this comment

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

Hmm I'm confused by their versioning. You're right for the 3.0 tag...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we resolve this, then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we resolve this, then?

Choose a reason for hiding this comment

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

what's about

Suggested change
if (!$sqlWalker->getConnection()->getDatabasePlatform() instanceof PostgreSQL94Platform) {
$platform = !$sqlWalker->getConnection()->getDatabasePlatform();
if (!$platform instanceof PostgreSQL94Platform && !$platform instanceof PostgreSQLPlatform) {

Copy link
Contributor Author

@piotaixr piotaixr Jan 10, 2022

Choose a reason for hiding this comment

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

Curious, I tried this locally. I was expecting this to fail with doctrine 3.1. (Doctrine 3.0 cannot be used, constraints from doctrine/orm preventing it)
Now, what I don't know is if its possible for an instance of AbstractPlatform (not Postgresql) to be given to this function. If yes (and the API does not prevent it, so I think its possible), the code will break with somethong else than Doctrine\DBAL\Exception which violates the interface contract.

I don't understand why you are pushing this much to have the check also done on PostgreSQLPlatform, can you elaborate more?

Copy link
Member

Choose a reason for hiding this comment

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

In the end we can deal with the deprecation later. I've just merged and released version 5. Thank you for all your effort.

tests/Mocks/DatabasePlatformMock.php Outdated Show resolved Hide resolved
tests/Query/PostgresqlTestCase.php Show resolved Hide resolved
@piotaixr
Copy link
Contributor Author

piotaixr commented Jan 8, 2022

Updated. I hope I didn't mess up anything.

@Hikariii
Copy link
Member

Hikariii commented Jan 8, 2022

Thank you, I will do a more extended test this week. I'm still a bit confused by the different PostgreSqlPlatform versions.
I'll sleep about it a bit. Maybe you have a good suggestion?

@piotaixr
Copy link
Contributor Author

piotaixr commented Jan 8, 2022

I just read about the 3.0 release of DBAL here: https://github.com/doctrine/dbal/releases/tag/3.0.0
They say they dropped support for postgresql 9.3 and older, making 9.4 the minimum supported version.

*/
protected function validatePlatform(SqlWalker$sqlWalker): void
{
if (!$sqlWalker->getConnection()->getDatabasePlatform() instanceof PostgreSqlPlatform) {
throw DBALException::notSupported(static::FUNCTION_NAME);
if (!$sqlWalker->getConnection()->getDatabasePlatform() instanceof PostgreSQL94Platform) {
Copy link

Choose a reason for hiding this comment

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

If you support doctrine 3.*, you should support both PostgreSQLPlatform and PostgreSQL94Platform.
(same for other platforms)

composer.json Outdated Show resolved Hide resolved
composer.json Outdated Show resolved Hide resolved
@piotaixr
Copy link
Contributor Author

I don't how thos happened, but the tests wouldn't pass until I added a dev dependency on doctrine/annotations.

@Hikariii Hikariii merged commit a5a2309 into ScientaNL:master Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incompatibility with doctrine/dbal 3
8 participants