migrations/Version20220804145926.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\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20220804145926 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $this->addSql('CREATE TABLE voting_answer (voting_id INT NOT NULL, answer_id INT NOT NULL, INDEX IDX_DCA799254254ACF8 (voting_id), INDEX IDX_DCA79925AA334807 (answer_id), PRIMARY KEY(voting_id, answer_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  18.         $this->addSql('ALTER TABLE voting_answer ADD CONSTRAINT FK_DCA799254254ACF8 FOREIGN KEY (voting_id) REFERENCES voting (id) ON DELETE CASCADE');
  19.         $this->addSql('ALTER TABLE voting_answer ADD CONSTRAINT FK_DCA79925AA334807 FOREIGN KEY (answer_id) REFERENCES answer (id) ON DELETE CASCADE');
  20.         $this->addSql('INSERT INTO voting_answer (answer_id, voting_id) SELECT id, voting_id FROM answer WHERE voting_id IS NOT NULL');
  21.         $this->addSql('ALTER TABLE answer DROP FOREIGN KEY FK_DADD4A254254ACF8');
  22.         $this->addSql('DROP INDEX IDX_DADD4A254254ACF8 ON answer');
  23.         $this->addSql('ALTER TABLE answer DROP voting_id');
  24.     }
  25.     public function down(Schema $schema): void
  26.     {
  27.         $this->addSql('ALTER TABLE answer ADD voting_id INT DEFAULT NULL');
  28.         $this->addSql('ALTER TABLE answer ADD CONSTRAINT FK_DADD4A254254ACF8 FOREIGN KEY (voting_id) REFERENCES voting (id)');
  29.         $this->addSql('CREATE INDEX IDX_DADD4A254254ACF8 ON answer (voting_id)');
  30.         $this->addSql('UPDATE answer INNER JOIN voting_answer ON voting_answer.answer_id = answer.id SET answer.voting_id = voting_answer.voting_id WHERE answer.id = voting_answer.answer_id');
  31.         $this->addSql('DROP TABLE voting_answer');
  32.     }
  33. }