migrations/Version20260430103000.php line 1

  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. final class Version20260430103000 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Add modality restrictions to certificate rules';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->abortIf(
  15.             !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySQL57Platform,
  16.             "Migration can only be executed safely on '\\Doctrine\\DBAL\\Platforms\\MySQL57Platform'."
  17.         );
  18.         $this->addSql('CREATE TABLE certificate_rule_modality (
  19.             certificate_rule_id INT NOT NULL,
  20.             taxonomy_value_id INT NOT NULL,
  21.             INDEX IDX_CERTIFICATE_RULE_MODALITY_RULE (certificate_rule_id),
  22.             INDEX IDX_CERTIFICATE_RULE_MODALITY_VALUE (taxonomy_value_id),
  23.             PRIMARY KEY(certificate_rule_id, taxonomy_value_id)
  24.         ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
  25.         $this->addSql('ALTER TABLE certificate_rule_modality ADD CONSTRAINT FK_CERTIFICATE_RULE_MODALITY_RULE FOREIGN KEY (certificate_rule_id) REFERENCES certificate_rule (id) ON DELETE CASCADE');
  26.         $this->addSql('ALTER TABLE certificate_rule_modality ADD CONSTRAINT FK_CERTIFICATE_RULE_MODALITY_VALUE FOREIGN KEY (taxonomy_value_id) REFERENCES taxonomy_value (id) ON DELETE CASCADE');
  27.     }
  28.     public function down(Schema $schema): void
  29.     {
  30.         $this->abortIf(
  31.             !$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySQL57Platform,
  32.             "Migration can only be executed safely on '\\Doctrine\\DBAL\\Platforms\\MySQL57Platform'."
  33.         );
  34.         $this->addSql('ALTER TABLE certificate_rule_modality DROP FOREIGN KEY FK_CERTIFICATE_RULE_MODALITY_RULE');
  35.         $this->addSql('ALTER TABLE certificate_rule_modality DROP FOREIGN KEY FK_CERTIFICATE_RULE_MODALITY_VALUE');
  36.         $this->addSql('DROP TABLE certificate_rule_modality');
  37.     }
  38. }