migrations/Version20230815223228.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use App\Entity\Target;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use Doctrine\Migrations\AbstractMigration;
  7. /**
  8.  * Modified migration that populates the tag and tag_scan tables
  9.  */
  10. final class Version20230815223228 extends AbstractMigration
  11. {
  12.     public function getDescription(): string
  13.     {
  14.         return '';
  15.     }
  16.     public function up(Schema $schema): void
  17.     {
  18.         // this up() migration is auto-generated, please modify it to your needs
  19.         $this->addSql('CREATE TABLE tag (type INT NOT NULL, label VARCHAR(50) NOT NULL, short_label VARCHAR(5) NOT NULL, UNIQUE INDEX UNIQ_389B783EA750E8 (label), UNIQUE INDEX UNIQ_389B7838EA2F0ED (short_label), PRIMARY KEY(type)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  20.         $this->addSql('CREATE TABLE tag_scan (tag_type INT NOT NULL, scan_id VARCHAR(32) NOT NULL, INDEX IDX_2ABC0C1862D1E89F (tag_type), INDEX IDX_2ABC0C182827AAD3 (scan_id), PRIMARY KEY(tag_type, scan_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  21.         $this->addSql('ALTER TABLE tag_scan ADD CONSTRAINT FK_2ABC0C1862D1E89F FOREIGN KEY (tag_type) REFERENCES tag (type)');
  22.         $this->addSql('ALTER TABLE tag_scan ADD CONSTRAINT FK_2ABC0C182827AAD3 FOREIGN KEY (scan_id) REFERENCES scans (id)');
  23.         // Custom SQL: Insert rows into the tag table
  24.         $this->addSql("INSERT INTO tag (type, label, short_label) VALUES (1, 'Deep Linking', 'DL')");
  25.         $this->addSql("INSERT INTO tag (type, label, short_label) VALUES (2, 'Homepage', 'HP')");
  26.         $this->addSql("INSERT INTO tag (type, label, short_label) VALUES (3, 'Malicious', 'ML')");
  27.     }
  28.     public function down(Schema $schema): void
  29.     {
  30.         // this down() migration is auto-generated, please modify it to your needs
  31.         $this->addSql('ALTER TABLE tag_scan DROP FOREIGN KEY FK_2ABC0C1862D1E89F');
  32.         $this->addSql('DROP TABLE tag');
  33.         $this->addSql('DROP TABLE tag_scan');
  34.     }
  35. }