vendor/bluue/shipments-bundle/migrations/Version20230725091406.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace ShipmentsBundleMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Symfony\Component\Uid\UuidV6;
  6. use Doctrine\Migrations\AbstractMigration;
  7. final class Version20230725091406 extends AbstractMigration
  8. {
  9.     public function up(Schema $schema): void
  10.     {
  11.         $this->addSql('ALTER TABLE shipments_bundle__burst ADD user_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid)\', ADD custom_text LONGTEXT DEFAULT NULL');
  12.         $this->addSql('ALTER TABLE shipments_bundle__burst ADD CONSTRAINT FK_561AB417A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)');
  13.         $this->addSql('CREATE INDEX IDX_561AB417A76ED395 ON shipments_bundle__burst (user_id)');
  14.     }
  15.     public function down(Schema $schema): void
  16.     {
  17.         $this->addSql('ALTER TABLE shipments_bundle__burst DROP FOREIGN KEY FK_561AB417A76ED395');
  18.         $this->addSql('DROP INDEX IDX_561AB417A76ED395 ON shipments_bundle__burst');
  19.         $this->addSql('ALTER TABLE shipments_bundle__burst DROP user_id, DROP custom_text');
  20.     }
  21.     public function postUp(Schema $schema): void
  22.     {
  23.         parent::postUp($schema);
  24.         $bursts $this->connection->executeQuery('SELECT * FROM shipments_bundle__burst')->fetchAllAssociative();
  25.         foreach ($bursts as $burst) {
  26.             $uuid UuidV6::fromBinary($burst['id'])->toRfc4122();
  27.             $uuid '0x' str_replace('-'''$uuid);
  28.             $createdByUuid UuidV6::fromBinary($burst['created_by_id'])->toRfc4122();
  29.             $createdByUuid '0x' str_replace('-'''$createdByUuid);
  30.             $this->connection->executeStatement("UPDATE shipments_bundle__burst SET user_id = " $createdByUuid " WHERE id = CAST(" $uuid " AS BINARY)");
  31.         }
  32.     }
  33. }