<?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 Version20220804145926 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
$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');
$this->addSql('ALTER TABLE voting_answer ADD CONSTRAINT FK_DCA799254254ACF8 FOREIGN KEY (voting_id) REFERENCES voting (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE voting_answer ADD CONSTRAINT FK_DCA79925AA334807 FOREIGN KEY (answer_id) REFERENCES answer (id) ON DELETE CASCADE');
$this->addSql('INSERT INTO voting_answer (answer_id, voting_id) SELECT id, voting_id FROM answer WHERE voting_id IS NOT NULL');
$this->addSql('ALTER TABLE answer DROP FOREIGN KEY FK_DADD4A254254ACF8');
$this->addSql('DROP INDEX IDX_DADD4A254254ACF8 ON answer');
$this->addSql('ALTER TABLE answer DROP voting_id');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE answer ADD voting_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE answer ADD CONSTRAINT FK_DADD4A254254ACF8 FOREIGN KEY (voting_id) REFERENCES voting (id)');
$this->addSql('CREATE INDEX IDX_DADD4A254254ACF8 ON answer (voting_id)');
$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');
$this->addSql('DROP TABLE voting_answer');
}
}