migrations/Version20230607020254.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. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20230607020254 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // cleanup the incident url and alerts tables before adding the foreign key constraint from alerts to scans
  18.         $this->addSql('DELETE FROM security_incident_urls WHERE security_incident_urls.alert_id in 
  19.                                          (select alerts.id from alerts where alerts.ad_id not in (select id from scans))');
  20.         $this->addSql('DELETE FROM alerts WHERE alerts.ad_id not in (select id from scans)');
  21.         $this->addSql('ALTER TABLE alerts CHANGE ad_id scan_id VARCHAR(32) NOT NULL');
  22.         $this->addSql('ALTER TABLE alerts ADD CONSTRAINT FK_F77AC06B2827AAD3 FOREIGN KEY (scan_id) REFERENCES scans (id)');
  23.         $this->addSql('CREATE INDEX IDX_F77AC06B2827AAD3 ON alerts (scan_id)');
  24.     }
  25.     public function down(Schema $schema): void
  26.     {
  27.         // this down() migration is auto-generated, please modify it to your needs
  28.         $this->addSql('ALTER TABLE alerts DROP FOREIGN KEY FK_F77AC06B2827AAD3');
  29.         $this->addSql('DROP INDEX IDX_F77AC06B2827AAD3 ON alerts');
  30.         $this->addSql('ALTER TABLE alerts CHANGE scan_id ad_id VARCHAR(32) NOT NULL');
  31.     }
  32. }