<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20220914164328 extends AbstractMigration
{
public function getDescription(): string
{
return 'add relation tags and tables for editor and solution';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE editor_tag (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE editor_tag_editor (editor_tag_id INT NOT NULL, editor_id INT NOT NULL, INDEX IDX_A8D50CEF50E57693 (editor_tag_id), INDEX IDX_A8D50CEF6995AC4C (editor_id), PRIMARY KEY(editor_tag_id, editor_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE reference_tag (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE reference_tag_solution (reference_tag_id INT NOT NULL, solution_id INT NOT NULL, INDEX IDX_885091F7A7B3D215 (reference_tag_id), INDEX IDX_885091F71C0BE183 (solution_id), PRIMARY KEY(reference_tag_id, solution_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE solution_tag (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE solution_tag_solution (solution_tag_id INT NOT NULL, solution_id INT NOT NULL, INDEX IDX_B9C0827CC924B477 (solution_tag_id), INDEX IDX_B9C0827C1C0BE183 (solution_id), PRIMARY KEY(solution_tag_id, solution_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE editor_tag_editor ADD CONSTRAINT FK_A8D50CEF50E57693 FOREIGN KEY (editor_tag_id) REFERENCES editor_tag (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE editor_tag_editor ADD CONSTRAINT FK_A8D50CEF6995AC4C FOREIGN KEY (editor_id) REFERENCES editor (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE reference_tag_solution ADD CONSTRAINT FK_885091F7A7B3D215 FOREIGN KEY (reference_tag_id) REFERENCES reference_tag (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE reference_tag_solution ADD CONSTRAINT FK_885091F71C0BE183 FOREIGN KEY (solution_id) REFERENCES solution (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE solution_tag_solution ADD CONSTRAINT FK_B9C0827CC924B477 FOREIGN KEY (solution_tag_id) REFERENCES solution_tag (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE solution_tag_solution ADD CONSTRAINT FK_B9C0827C1C0BE183 FOREIGN KEY (solution_id) REFERENCES solution (id) ON DELETE CASCADE');
$this->addSql('DROP INDEX UNIQ_CCF1F1BAF98F144A ON editor');
$this->addSql('ALTER TABLE editor DROP labels');
$this->addSql('ALTER TABLE solution DROP main_references, DROP tags');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE editor_tag_editor DROP FOREIGN KEY FK_A8D50CEF50E57693');
$this->addSql('ALTER TABLE editor_tag_editor DROP FOREIGN KEY FK_A8D50CEF6995AC4C');
$this->addSql('ALTER TABLE reference_tag_solution DROP FOREIGN KEY FK_885091F7A7B3D215');
$this->addSql('ALTER TABLE reference_tag_solution DROP FOREIGN KEY FK_885091F71C0BE183');
$this->addSql('ALTER TABLE solution_tag_solution DROP FOREIGN KEY FK_B9C0827CC924B477');
$this->addSql('ALTER TABLE solution_tag_solution DROP FOREIGN KEY FK_B9C0827C1C0BE183');
$this->addSql('DROP TABLE editor_tag');
$this->addSql('DROP TABLE editor_tag_editor');
$this->addSql('DROP TABLE reference_tag');
$this->addSql('DROP TABLE reference_tag_solution');
$this->addSql('DROP TABLE solution_tag');
$this->addSql('DROP TABLE solution_tag_solution');
$this->addSql('ALTER TABLE solution ADD main_references VARCHAR(255) DEFAULT NULL, ADD tags VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE editor ADD labels LONGTEXT DEFAULT NULL');
$this->addSql('CREATE UNIQUE INDEX UNIQ_CCF1F1BAF98F144A ON editor (editor_logo_id)');
}
}