|
@@ -0,0 +1,61 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+declare(strict_types=1);
|
|
|
+
|
|
|
+namespace DoctrineMigrations;
|
|
|
+
|
|
|
+use Doctrine\DBAL\Schema\Schema;
|
|
|
+use Doctrine\Migrations\AbstractMigration;
|
|
|
+
|
|
|
+
|
|
|
+ * Auto-generated Migration: Please modify to your needs!
|
|
|
+ */
|
|
|
+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)\'');
|
|
|
+ }
|
|
|
+}
|