<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230607020254 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// cleanup the incident url and alerts tables before adding the foreign key constraint from alerts to scans
$this->addSql('DELETE FROM security_incident_urls WHERE security_incident_urls.alert_id in
(select alerts.id from alerts where alerts.ad_id not in (select id from scans))');
$this->addSql('DELETE FROM alerts WHERE alerts.ad_id not in (select id from scans)');
$this->addSql('ALTER TABLE alerts CHANGE ad_id scan_id VARCHAR(32) NOT NULL');
$this->addSql('ALTER TABLE alerts ADD CONSTRAINT FK_F77AC06B2827AAD3 FOREIGN KEY (scan_id) REFERENCES scans (id)');
$this->addSql('CREATE INDEX IDX_F77AC06B2827AAD3 ON alerts (scan_id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE alerts DROP FOREIGN KEY FK_F77AC06B2827AAD3');
$this->addSql('DROP INDEX IDX_F77AC06B2827AAD3 ON alerts');
$this->addSql('ALTER TABLE alerts CHANGE scan_id ad_id VARCHAR(32) NOT NULL');
}
}