sonata-project / SonataUserBundle

Symfony SonataUserBundle
https://docs.sonata-project.org/projects/SonataUserBundle
MIT License
339 stars 488 forks source link

Make the code compatible with DBAL 3 and 4 by swithing the type when… #1685

Open rande opened 4 months ago

rande commented 4 months ago

Make the code compatible with DBAL 3 and 4 by swithing the type when the Mapping is loaded

I am targeting this branch, because because it introduces a non necessary BC break. For reference: https://github.com/sonata-project/SonataUserBundle/pull/1677

Changelog

### Removed
- BaseUser3 doctrine definition

### Added
- Mapping listener to make the same entity works with DBAL 2, 3 or 4

To do

VincentLanglet commented 4 months ago

There is the error

In MappingException.php line 112:

  The column type of attribute 'roles' on class 'Sonata\UserBundle\Tests\App\  
  Entity\User' could not be changed. 
rande commented 4 months ago

@VincentLanglet hopefully this is good to go!

VincentLanglet commented 4 months ago

The doc need to be updated too, in order to remove reference of BaseUser3 https://github.com/sonata-project/SonataUserBundle/blob/a6169f318ad30a46ced640fad58a686e695e86f0/docs/reference/installation.rst#doctrine-orm-configuration

Hanmac commented 3 months ago

We probably need to find a way to Migrate the User Data?

My current attempt is this Doctrine Migration file:

$result = $this->connection->executeQuery('SELECT id, roles FROM fos_user_user');
foreach ($result->fetchAllAssociative() as $item) {
    $this->connection->update('fos_user_user', [
        'roles' => json_encode(unserialize($item['roles']))
    ], [
        'id' => $item['id']
    ]);
}

$this->addSql('ALTER TABLE fos_user_user CHANGE roles roles JSON NOT NULL');
Hanmac commented 1 month ago

@VincentLanglet @greg0ire how is the status for this MR?

And do we need an update Script for existing data?

VincentLanglet commented 1 month ago

@VincentLanglet @greg0ire how is the status for this MR?

And do we need an update Script for existing data?

See https://github.com/sonata-project/SonataUserBundle/pull/1685#issuecomment-2113465869

You can do it if you want this to be merged

Hanmac commented 1 month ago

@VincentLanglet the Doc update is one thing, should we try to something like my Update Script in a more automated way?

https://github.com/sonata-project/SonataUserBundle/pull/1685#issuecomment-2166019519

Or is the Dev alone with this? (i also don't know if my way is the correct one)

VincentLanglet commented 1 month ago

@VincentLanglet the Doc update is one thing, should we try to something like my Update Script in a more automated way?

#1685 (comment)

Or is the Dev alone with this? (i also don't know if my way is the correct one)

We can document some helper/migrations about how to move from DBAL 3 to DBAL 4 but this cannot be included inside the SonataUserBundle code since we cannot be sure