SonataUserBundle
SonataUserBundle copied to clipboard
Make the code compatible with DBAL 3 and 4 by swithing the type when…
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;
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 hopefully this is good to go!
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
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');
@VincentLanglet @greg0ire how is the status for this MR?
And do we need an update Script for existing data?
@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 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 the Doc update is one thing, should we try to something like my Update Script in a more automated way?
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.
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.
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.