12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- declare(strict_types=1);
- namespace DoctrineMigrations;
- use Doctrine\DBAL\Schema\Schema;
- use Doctrine\Migrations\AbstractMigration;
- final class Version20240803144323 extends AbstractMigration
- {
- public function getDescription(): string
- {
- return '';
- }
- public function up(Schema $schema): void
- {
- $this->addSql('
- ALTER TABLE user MODIFY roles LONGTEXT
- ');
-
- $users = $this->connection->fetchAllAssociative('SELECT id, roles FROM user');
-
- foreach ($users as $user) {
- $roles = unserialize($user['roles']);
- $jsonRoles = json_encode($roles);
- $this->addSql('UPDATE user SET roles = ? WHERE id = ?', [$jsonRoles, $user['id']]);
- }
- $this->addSql('
- ALTER TABLE user MODIFY roles JSON
- ');
-
- $this->addSql('ALTER TABLE user CHANGE roles roles JSON NOT NULL');
-
- }
- public function down(Schema $schema): void
- {
-
-
- $users = $this->connection->fetchAllAssociative('SELECT id, roles FROM user');
-
- foreach ($users as $user) {
- $roles = json_decode($user['roles'], true);
- $serializedRoles = serialize($roles);
- $this->addSql('UPDATE user SET roles = ? WHERE id = ?', [$serializedRoles, $user['id']]);
- }
- $this->addSql('
- ALTER TABLE user MODIFY roles LONGTEXT
- ');
- $this->addSql('ALTER TABLE user CHANGE roles roles LONGTEXT NOT NULL COMMENT \'(DC2Type:array)\'');
- }
- }
|