migrations/Version20220914164328.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. final class Version20220914164328 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'add relation tags and tables for editor and solution';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $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');
  15.         $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');
  16.         $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');
  17.         $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');
  18.         $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');
  19.         $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');
  20.         $this->addSql('ALTER TABLE editor_tag_editor ADD CONSTRAINT FK_A8D50CEF50E57693 FOREIGN KEY (editor_tag_id) REFERENCES editor_tag (id) ON DELETE CASCADE');
  21.         $this->addSql('ALTER TABLE editor_tag_editor ADD CONSTRAINT FK_A8D50CEF6995AC4C FOREIGN KEY (editor_id) REFERENCES editor (id) ON DELETE CASCADE');
  22.         $this->addSql('ALTER TABLE reference_tag_solution ADD CONSTRAINT FK_885091F7A7B3D215 FOREIGN KEY (reference_tag_id) REFERENCES reference_tag (id) ON DELETE CASCADE');
  23.         $this->addSql('ALTER TABLE reference_tag_solution ADD CONSTRAINT FK_885091F71C0BE183 FOREIGN KEY (solution_id) REFERENCES solution (id) ON DELETE CASCADE');
  24.         $this->addSql('ALTER TABLE solution_tag_solution ADD CONSTRAINT FK_B9C0827CC924B477 FOREIGN KEY (solution_tag_id) REFERENCES solution_tag (id) ON DELETE CASCADE');
  25.         $this->addSql('ALTER TABLE solution_tag_solution ADD CONSTRAINT FK_B9C0827C1C0BE183 FOREIGN KEY (solution_id) REFERENCES solution (id) ON DELETE CASCADE');
  26.         $this->addSql('DROP INDEX UNIQ_CCF1F1BAF98F144A ON editor');
  27.         $this->addSql('ALTER TABLE editor DROP labels');
  28.         $this->addSql('ALTER TABLE solution DROP main_references, DROP tags');
  29.     }
  30.     public function down(Schema $schema): void
  31.     {
  32.         $this->addSql('ALTER TABLE editor_tag_editor DROP FOREIGN KEY FK_A8D50CEF50E57693');
  33.         $this->addSql('ALTER TABLE editor_tag_editor DROP FOREIGN KEY FK_A8D50CEF6995AC4C');
  34.         $this->addSql('ALTER TABLE reference_tag_solution DROP FOREIGN KEY FK_885091F7A7B3D215');
  35.         $this->addSql('ALTER TABLE reference_tag_solution DROP FOREIGN KEY FK_885091F71C0BE183');
  36.         $this->addSql('ALTER TABLE solution_tag_solution DROP FOREIGN KEY FK_B9C0827CC924B477');
  37.         $this->addSql('ALTER TABLE solution_tag_solution DROP FOREIGN KEY FK_B9C0827C1C0BE183');
  38.         $this->addSql('DROP TABLE editor_tag');
  39.         $this->addSql('DROP TABLE editor_tag_editor');
  40.         $this->addSql('DROP TABLE reference_tag');
  41.         $this->addSql('DROP TABLE reference_tag_solution');
  42.         $this->addSql('DROP TABLE solution_tag');
  43.         $this->addSql('DROP TABLE solution_tag_solution');
  44.         $this->addSql('ALTER TABLE solution ADD main_references VARCHAR(255) DEFAULT NULL, ADD tags VARCHAR(255) DEFAULT NULL');
  45.         $this->addSql('ALTER TABLE editor ADD labels LONGTEXT DEFAULT NULL');
  46.         $this->addSql('CREATE UNIQUE INDEX UNIQ_CCF1F1BAF98F144A ON editor (editor_logo_id)');
  47.     }
  48. }