SonataUserBundle icon indicating copy to clipboard operation
SonataUserBundle copied to clipboard

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

Open rande opened this issue 1 year ago • 9 comments

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

  • [x] Review PR;

rande avatar May 15 '24 15:05 rande

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. 

VincentLanglet avatar May 15 '24 15:05 VincentLanglet

@VincentLanglet hopefully this is good to go!

rande avatar May 15 '24 17:05 rande

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

VincentLanglet avatar May 15 '24 21:05 VincentLanglet

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 avatar Jun 13 '24 15:06 Hanmac

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

And do we need an update Script for existing data?

Hanmac avatar Aug 15 '24 08:08 Hanmac

@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

VincentLanglet avatar Aug 15 '24 18:08 VincentLanglet

@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)

Hanmac avatar Aug 16 '24 15:08 Hanmac

@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

  • when the user will update his DBAL version
  • if he want to execute some data migration or doing something else.

VincentLanglet avatar Aug 16 '24 17:08 VincentLanglet

I am not sure on what solution to apply here, but right now it is not possible to update to dbal 4, even if userbundle says we are compatible, as soon as you update, the command: doctrine:schema:validate starts complaining:

/usr/app $ console doctrine:schema:validate

Mapping
-------

 [FAIL] The entity-class Sonata\UserBundle\Entity\BaseUser mapping is invalid:
 * The field 'Sonata\UserBundle\Entity\BaseUser#roles' uses a non-existent type 'array'.

Even if I am not using that mapping file because I switched to the other interface.

jordisala1991 avatar Jan 27 '25 12:01 jordisala1991

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jul 26 '25 13:07 github-actions[bot]