migrations/Version20220525235557.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\Migrations\AbstractMigration;
  7. use Symfony\Component\Uid\Ulid;
  8. use Symfony\Component\Uid\Uuid;
  9. /**
  10.  * Auto-generated Migration: Please modify to your needs!
  11.  */
  12. final class Version20220525235557 extends AbstractMigration
  13. {
  14.     public function getDescription(): string
  15.     {
  16.         return '';
  17.     }
  18.     public function up(Schema $schema): void
  19.     {
  20.         // this up() migration is auto-generated, please modify it to your needs
  21.         $this->addSql('ALTER TABLE campaign ADD access_token BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid)\'');
  22.         $campaigns $this->connection->createQueryBuilder()
  23.             ->select('c.id')
  24.             ->from('campaign''c')
  25.             ->orderBy('c.id')
  26.             ->executeQuery()
  27.             ->fetchFirstColumn();
  28.         foreach ($campaigns as $id) {
  29.             usleep(100);
  30.             $this->addSql('UPDATE campaign SET access_token = :accessToken WHERE id = :id', [
  31.                 'id' => $id,
  32.                 'accessToken' => Uuid::v6()->toBinary(),
  33.             ]);
  34.         }
  35.         $this->addSql('CREATE UNIQUE INDEX UNIQ_1F1512DDB6A2DD68 ON campaign (access_token)');
  36.     }
  37.     public function down(Schema $schema): void
  38.     {
  39.         // this down() migration is auto-generated, please modify it to your needs
  40.         $this->addSql('DROP INDEX UNIQ_1F1512DDB6A2DD68 ON campaign');
  41.         $this->addSql('ALTER TABLE campaign DROP access_token');
  42.     }
  43.     public function isTransactional(): bool
  44.     {
  45.         return false;
  46.     }
  47. }