<?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 Version20190711120305 extends AbstractMigration
{
    public function getDescription() : string
    {
        return '';
    }

    public function up(Schema $schema) : void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

        $this->addSql('CREATE TABLE campaign_landing_page_pa (id INT AUTO_INCREMENT NOT NULL, landing_page_id INT NOT NULL, value INT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, updated_at DATETIME DEFAULT NULL, INDEX IDX_49CFFF47DF122DC5 (landing_page_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
        $this->addSql('CREATE TABLE campaign_landing_page_backlinks (id INT AUTO_INCREMENT NOT NULL, landing_page_id INT NOT NULL, description LONGTEXT NOT NULL, created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, updated_at DATETIME DEFAULT NULL, INDEX IDX_38A6C2EBDF122DC5 (landing_page_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
        $this->addSql('ALTER TABLE campaign_landing_page_pa ADD CONSTRAINT FK_49CFFF47DF122DC5 FOREIGN KEY (landing_page_id) REFERENCES campaign_landing_page (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE campaign_landing_page_backlinks ADD CONSTRAINT FK_38A6C2EBDF122DC5 FOREIGN KEY (landing_page_id) REFERENCES campaign_landing_page (id) ON DELETE CASCADE');
        $this->addSql('ALTER TABLE campaign_landing_page ADD latest_page_authority_check_id INT DEFAULT NULL, ADD latest_backlinks_report_id INT DEFAULT NULL');
        $this->addSql('ALTER TABLE campaign_landing_page ADD CONSTRAINT FK_DA1719A7B2C5DEF5 FOREIGN KEY (latest_page_authority_check_id) REFERENCES campaign_landing_page_pa (id) ON DELETE SET NULL');
        $this->addSql('ALTER TABLE campaign_landing_page ADD CONSTRAINT FK_DA1719A778AFECD1 FOREIGN KEY (latest_backlinks_report_id) REFERENCES campaign_landing_page_backlinks (id) ON DELETE SET NULL');
        $this->addSql('CREATE UNIQUE INDEX UNIQ_DA1719A7B2C5DEF5 ON campaign_landing_page (latest_page_authority_check_id)');
        $this->addSql('CREATE UNIQUE INDEX UNIQ_DA1719A778AFECD1 ON campaign_landing_page (latest_backlinks_report_id)');
    }

    public function down(Schema $schema) : void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

        $this->addSql('ALTER TABLE campaign_landing_page DROP FOREIGN KEY FK_DA1719A7B2C5DEF5');
        $this->addSql('ALTER TABLE campaign_landing_page DROP FOREIGN KEY FK_DA1719A778AFECD1');
        $this->addSql('DROP TABLE campaign_landing_page_pa');
        $this->addSql('DROP TABLE campaign_landing_page_backlinks');
        $this->addSql('DROP INDEX UNIQ_DA1719A7B2C5DEF5 ON campaign_landing_page');
        $this->addSql('DROP INDEX UNIQ_DA1719A778AFECD1 ON campaign_landing_page');
        $this->addSql('ALTER TABLE campaign_landing_page DROP latest_page_authority_check_id, DROP latest_backlinks_report_id');
    }
}
