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

Compatibility with doctrine dbal 4 #1677

Merged
merged 3 commits into from
Apr 18, 2024

Conversation

RobinDev
Copy link
Contributor

@RobinDev RobinDev commented Feb 27, 2024

Compatibility with doctrine dbal 4

Just switching the deprecated array type to json - cf Upgrade Guide

I am targeting this branch, because it's a patch wich is not introducing bc break.

About BC Break, i am not sure, because it's required to update from unserialized to json encoded.

Changelog

### Added
- BaseUser3 with roles mapped type as `json` to be compatible with ORM 3

@RobinDev RobinDev closed this Feb 27, 2024
@RobinDev RobinDev reopened this Feb 27, 2024
@RobinDev
Copy link
Contributor Author

RobinDev commented Feb 27, 2024

About BC Break, i am not sure, because it's required to update from unserialized to json encoded.

I run a migration on a current project using sonataUserBundle, should I add it to this PR ?

<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version1709056840 extends AbstractMigration
{
    public function up(Schema $schema): void
    { 
        $rows = $this->connection->fetchAllAssociative('SELECT id,roles FROM user');

        /** @var array{'id': scalar, 'roles': string}[] $rows */
        foreach ($rows as $row) {
            $id = $row['id'];
            $roles = json_encode(unserialize($row['roles']));
            $this->connection->executeQuery('UPDATE user SET roles = :roles WHERE id = :id', ['roles' => $roles, 'id' => $id]);
        }
    }
}

@RobinDev RobinDev changed the title Compatibility with doctrine dbal 3 Compatibility with doctrine dbal 4 Feb 27, 2024
@VincentLanglet VincentLanglet requested review from a team and jordisala1991 March 8, 2024 02:15
@VincentLanglet
Copy link
Member

WDYT @jordisala1991 ? Should we consider this as a BC break ?

@core23
Copy link
Member

core23 commented Mar 8, 2024

I would handle this as a BC break, because without a migration you can't load the roles anymore.

As this bundle does not provide any auto-migration script, there is no way to run composer update on a project without any problems.

@VincentLanglet
Copy link
Member

I would handle this as a BC break, because without a migration you can't load the roles anymore.

As this bundle does not provide any auto-migration script, there is no way to run composer update on a project without any problems.

Yeah I was afraid about this.

Maybe we could have two files BaseUser.orm2.xml and BaseUser.orm3.xml and one of the two solution

  • Automatically load the right file based on the ORM version
  • Adding a configuration option to tell which file should be loaded

Wdyt @RobinDev ?

@RobinDev
Copy link
Contributor Author

RobinDev commented Mar 8, 2024

I think your suggestions permit to ship it now and maintain compatibility with dbal 3 for a moment... but it's adding some complexity to maintain.

I would have a preference to target the 6.X branch wich is available via composer.

It will permit for the projects that required an upgrade of dbal to target the next version.

Feel free to modify my PR, i will not be available during the next 8 days.

@RobinDev
Copy link
Contributor Author

I made an other PR on 6.X #1680

@RobinDev RobinDev closed this Mar 20, 2024
@VincentLanglet
Copy link
Member

VincentLanglet commented Mar 20, 2024

I think your suggestions permit to ship it now and maintain compatibility with dbal 3 for a moment... but it's adding some complexity to maintain.

I would have a preference to target the 6.X branch wich is available via composer.

There is less complexity maintaining one branch, even with some config loaded conditionally rather than maintaining two branch. We don't plan to release 6.x branch soon, so I would say we don't plan to merge any PR on this branch.

So we have to find another solution...

@VincentLanglet
Copy link
Member

Maybe you have a suggestion @jordisala1991 @dmaicher ?

@RobinDev
Copy link
Contributor Author

I follow your suggestions.

So if an user want to use doctrine/orm ^3 :

  • the user must extend is entity with BaseUser3 instead of BaseUser
  • the user must manage the migration if the entity was existing (sonata/user-bundle upgrade)

@VincentLanglet
Copy link
Member

I follow your suggestions.

So if an user want to use doctrine/orm ^3 :

  • the user must extend is entity with BaseUser3 instead of BaseUser
  • the user must manage the migration if the entity was existing (sonata/user-bundle upgrade)

Seems like a nice solution without bc break. WDYT @core23 ?

@VincentLanglet
Copy link
Member

I fixed the cs, you can rebase #1681

@RobinDev
Copy link
Contributor Author

Done

@VincentLanglet
Copy link
Member

Done

Thanks, I'll try to get some opinions from others reviewers.

Ping @phansys @core23 @jordisala1991 @dmaicher @franmomu wdyt ?

@VincentLanglet VincentLanglet merged commit d646f09 into sonata-project:5.x Apr 18, 2024
23 checks passed
@VincentLanglet
Copy link
Member

Thanks @RobinDev

@rande
Copy link
Member

rande commented May 14, 2024

Hello, coming late to this change.

All this code can be updated to use a Doctrine Listener to change the mapping type without creating a new class and definition, this will make the migration path way easier.

This is why we have the https://github.com/sonata-project/sonata-doctrine-extensions/blob/2.x/src/Mapper/DoctrineCollector.php in the sonata-project/doctrine-extensions project

@rande
Copy link
Member

rande commented May 15, 2024

Ping @RobinDev @VincentLanglet - Do you want me to do a MR on this to avoid introducing a BC break ?

@VincentLanglet
Copy link
Member

Ping @RobinDev @VincentLanglet - Do you want me to do a MR on this to avoid introducing a BC break ?

Sure !

@rande
Copy link
Member

rande commented May 15, 2024

Done: #1685

@Hanmac
Copy link
Contributor

Hanmac commented Jun 13, 2024

Are we sure about that array type?

https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#array says:

This type is deprecated since 3.4.0, use json instead.

right now, I get:

Unknown column type "array" requested.

Also we might need some better way to migrate the roles data?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants