<?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 Version20190109171819 extends AbstractMigration
{
    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('ALTER TABLE charte DROP FOREIGN KEY FK_3484E5A63DA5256D');
        $this->addSql('ALTER TABLE charte DROP FOREIGN KEY FK_3484E5A6F915CFE');
        $this->addSql('ALTER TABLE comptoir DROP FOREIGN KEY FK_A6E2C35EF915CFE');
        $this->addSql('ALTER TABLE faq DROP FOREIGN KEY FK_E8FF75CCF915CFE');
        $this->addSql('ALTER TABLE news DROP FOREIGN KEY FK_1DD39950F915CFE');
        $this->addSql('ALTER TABLE prestataire DROP FOREIGN KEY FK_60A264803DA5256D');
        $this->addSql('DROP TABLE fichier');
        $this->addSql('DROP INDEX UNIQ_1DD39950F915CFE ON news');
        $this->addSql('ALTER TABLE news CHANGE fichier_id media_id INT DEFAULT NULL');
        $this->addSql('ALTER TABLE news ADD CONSTRAINT FK_1DD39950EA9FDD75 FOREIGN KEY (media_id) REFERENCES media__media (id)');
        $this->addSql('CREATE INDEX IDX_1DD39950EA9FDD75 ON news (media_id)');
        $this->addSql('DROP INDEX UNIQ_A6E2C35EF915CFE ON comptoir');
        $this->addSql('ALTER TABLE comptoir CHANGE fichier_id media_id INT DEFAULT NULL');
        $this->addSql('ALTER TABLE comptoir ADD CONSTRAINT FK_A6E2C35EEA9FDD75 FOREIGN KEY (media_id) REFERENCES media__media (id)');
        $this->addSql('CREATE INDEX IDX_A6E2C35EEA9FDD75 ON comptoir (media_id)');
        $this->addSql('DROP INDEX UNIQ_3484E5A6F915CFE ON charte');
        $this->addSql('DROP INDEX UNIQ_3484E5A63DA5256D ON charte');
        $this->addSql('ALTER TABLE charte ADD media_id INT DEFAULT NULL, ADD text LONGTEXT DEFAULT NULL, DROP image_id, DROP fichier_id');
        $this->addSql('ALTER TABLE charte ADD CONSTRAINT FK_3484E5A6EA9FDD75 FOREIGN KEY (media_id) REFERENCES media__media (id)');
        $this->addSql('CREATE INDEX IDX_3484E5A6EA9FDD75 ON charte (media_id)');
        $this->addSql('DROP INDEX UNIQ_60A264803DA5256D ON prestataire');
        $this->addSql('ALTER TABLE prestataire CHANGE image_id media_id INT DEFAULT NULL');
        $this->addSql('ALTER TABLE prestataire ADD CONSTRAINT FK_60A26480EA9FDD75 FOREIGN KEY (media_id) REFERENCES media__media (id)');
        $this->addSql('CREATE INDEX IDX_60A26480EA9FDD75 ON prestataire (media_id)');
        $this->addSql('DROP INDEX UNIQ_E8FF75CCF915CFE ON faq');
        $this->addSql('ALTER TABLE faq ADD text LONGTEXT DEFAULT NULL, ADD name VARCHAR(150) NOT NULL, ADD slug VARCHAR(150) NOT NULL, ADD content LONGTEXT DEFAULT NULL, CHANGE fichier_id media_id INT DEFAULT NULL');
        $this->addSql('ALTER TABLE faq ADD CONSTRAINT FK_E8FF75CCEA9FDD75 FOREIGN KEY (media_id) REFERENCES media__media (id)');
        $this->addSql('CREATE UNIQUE INDEX UNIQ_E8FF75CC989D9B62 ON faq (slug)');
        $this->addSql('CREATE INDEX IDX_E8FF75CCEA9FDD75 ON faq (media_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('CREATE TABLE fichier (id INT AUTO_INCREMENT NOT NULL, path LONGTEXT DEFAULT NULL COLLATE utf8mb4_unicode_ci, discr VARCHAR(255) NOT NULL COLLATE utf8mb4_unicode_ci, width INT DEFAULT NULL, height INT DEFAULT NULL, enabled TINYINT(1) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB COMMENT = \'\' ');
        $this->addSql('ALTER TABLE charte DROP FOREIGN KEY FK_3484E5A6EA9FDD75');
        $this->addSql('DROP INDEX IDX_3484E5A6EA9FDD75 ON charte');
        $this->addSql('ALTER TABLE charte ADD fichier_id INT DEFAULT NULL, DROP text, CHANGE media_id image_id INT DEFAULT NULL');
        $this->addSql('ALTER TABLE charte ADD CONSTRAINT FK_3484E5A63DA5256D FOREIGN KEY (image_id) REFERENCES fichier (id)');
        $this->addSql('ALTER TABLE charte ADD CONSTRAINT FK_3484E5A6F915CFE FOREIGN KEY (fichier_id) REFERENCES fichier (id)');
        $this->addSql('CREATE UNIQUE INDEX UNIQ_3484E5A6F915CFE ON charte (fichier_id)');
        $this->addSql('CREATE UNIQUE INDEX UNIQ_3484E5A63DA5256D ON charte (image_id)');
        $this->addSql('ALTER TABLE comptoir DROP FOREIGN KEY FK_A6E2C35EEA9FDD75');
        $this->addSql('DROP INDEX IDX_A6E2C35EEA9FDD75 ON comptoir');
        $this->addSql('ALTER TABLE comptoir CHANGE media_id fichier_id INT DEFAULT NULL');
        $this->addSql('ALTER TABLE comptoir ADD CONSTRAINT FK_A6E2C35EF915CFE FOREIGN KEY (fichier_id) REFERENCES fichier (id)');
        $this->addSql('CREATE UNIQUE INDEX UNIQ_A6E2C35EF915CFE ON comptoir (fichier_id)');
        $this->addSql('ALTER TABLE faq DROP FOREIGN KEY FK_E8FF75CCEA9FDD75');
        $this->addSql('DROP INDEX UNIQ_E8FF75CC989D9B62 ON faq');
        $this->addSql('DROP INDEX IDX_E8FF75CCEA9FDD75 ON faq');
        $this->addSql('ALTER TABLE faq DROP text, DROP name, DROP slug, DROP content, CHANGE media_id fichier_id INT DEFAULT NULL');
        $this->addSql('ALTER TABLE faq ADD CONSTRAINT FK_E8FF75CCF915CFE FOREIGN KEY (fichier_id) REFERENCES fichier (id)');
        $this->addSql('CREATE UNIQUE INDEX UNIQ_E8FF75CCF915CFE ON faq (fichier_id)');
        $this->addSql('ALTER TABLE news DROP FOREIGN KEY FK_1DD39950EA9FDD75');
        $this->addSql('DROP INDEX IDX_1DD39950EA9FDD75 ON news');
        $this->addSql('ALTER TABLE news CHANGE media_id fichier_id INT DEFAULT NULL');
        $this->addSql('ALTER TABLE news ADD CONSTRAINT FK_1DD39950F915CFE FOREIGN KEY (fichier_id) REFERENCES fichier (id)');
        $this->addSql('CREATE UNIQUE INDEX UNIQ_1DD39950F915CFE ON news (fichier_id)');
        $this->addSql('ALTER TABLE prestataire DROP FOREIGN KEY FK_60A26480EA9FDD75');
        $this->addSql('DROP INDEX IDX_60A26480EA9FDD75 ON prestataire');
        $this->addSql('ALTER TABLE prestataire CHANGE media_id image_id INT DEFAULT NULL');
        $this->addSql('ALTER TABLE prestataire ADD CONSTRAINT FK_60A264803DA5256D FOREIGN KEY (image_id) REFERENCES fichier (id)');
        $this->addSql('CREATE UNIQUE INDEX UNIQ_60A264803DA5256D ON prestataire (image_id)');
    }
}
