<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20200601112949 extends AbstractMigration
{
/**
* @param Schema $schema
*/
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 hoard_archaeology_site_context_detail (hoard_id INT NOT NULL, archaeology_site_context_detail_id INT NOT NULL, INDEX IDX_8A9E119C762C4B4D (hoard_id), INDEX IDX_8A9E119C810A938 (archaeology_site_context_detail_id), PRIMARY KEY(hoard_id, archaeology_site_context_detail_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
$this->addSql('CREATE TABLE hoard_archaeology_context_nature (hoard_id INT NOT NULL, archaeology_context_nature_id INT NOT NULL, INDEX IDX_B0220C28762C4B4D (hoard_id), INDEX IDX_B0220C2874F571E5 (archaeology_context_nature_id), PRIMARY KEY(hoard_id, archaeology_context_nature_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
$this->addSql('ALTER TABLE hoard_archaeology_site_context_detail ADD CONSTRAINT FK_8A9E119C762C4B4D FOREIGN KEY (hoard_id) REFERENCES hoard (id)');
$this->addSql('ALTER TABLE hoard_archaeology_site_context_detail ADD CONSTRAINT FK_8A9E119C810A938 FOREIGN KEY (archaeology_site_context_detail_id) REFERENCES archaeology_site_context_detail (id)');
$this->addSql('ALTER TABLE hoard_archaeology_context_nature ADD CONSTRAINT FK_B0220C28762C4B4D FOREIGN KEY (hoard_id) REFERENCES hoard (id)');
$this->addSql('ALTER TABLE hoard_archaeology_context_nature ADD CONSTRAINT FK_B0220C2874F571E5 FOREIGN KEY (archaeology_context_nature_id) REFERENCES archaeology_context_nature (id)');
$this->addSql('INSERT INTO hoard_archaeology_context_nature (hoard_id, archaeology_context_nature_id) SELECT id, archaeology_context_nature_id FROM hoard WHERE archaeology_context_nature_id IS NOT NULL');
$this->addSql('INSERT INTO hoard_archaeology_site_context_detail (hoard_id, archaeology_site_context_detail_id) SELECT id, archaeology_site_context_detail_id FROM hoard WHERE archaeology_site_context_detail_id IS NOT NULL');
$this->addSql('ALTER TABLE archaeology_site_context CHANGE sort_value sort_value DOUBLE PRECISION DEFAULT NULL');
$this->addSql('ALTER TABLE hoard DROP FOREIGN KEY archaeology_context_nature');
$this->addSql('ALTER TABLE hoard DROP FOREIGN KEY archaeology_site_context_detail');
$this->addSql('ALTER TABLE hoard DROP archaeology_context_nature_id, DROP archaeology_site_context_detail_id');
$this->addSql('ALTER TABLE hoard_audit DROP archaeology_site_context_detail_id, DROP archaeology_context_nature_id');
$this->addSql('ALTER TABLE archaeology_context_nature CHANGE sort_value sort_value DOUBLE PRECISION DEFAULT NULL');
$this->addSql('ALTER TABLE archaeology_site_context_detail CHANGE sort_value sort_value DOUBLE PRECISION DEFAULT NULL');
}
/**
* @param Schema $schema
*/
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('DROP TABLE hoard_archaeology_site_context_detail');
$this->addSql('DROP TABLE hoard_archaeology_context_nature');
$this->addSql('ALTER TABLE archaeology_context_nature CHANGE sort_value sort_value DOUBLE PRECISION DEFAULT \'0\' NOT NULL');
$this->addSql('ALTER TABLE archaeology_site_context CHANGE sort_value sort_value DOUBLE PRECISION DEFAULT \'0\' NOT NULL');
$this->addSql('ALTER TABLE archaeology_site_context_detail CHANGE sort_value sort_value DOUBLE PRECISION DEFAULT \'0\' NOT NULL');
$this->addSql('ALTER TABLE hoard ADD archaeology_context_nature_id INT DEFAULT NULL, ADD archaeology_site_context_detail_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE hoard ADD CONSTRAINT archaeology_context_nature FOREIGN KEY (archaeology_context_nature_id) REFERENCES archaeology_context_nature (id) ON UPDATE NO ACTION ON DELETE NO ACTION');
$this->addSql('ALTER TABLE hoard ADD CONSTRAINT archaeology_site_context_detail FOREIGN KEY (archaeology_site_context_detail_id) REFERENCES archaeology_site_context_detail (id) ON UPDATE NO ACTION ON DELETE NO ACTION');
$this->addSql('CREATE INDEX FK_12E633E6810A938 ON hoard (archaeology_site_context_detail_id)');
$this->addSql('CREATE INDEX FK_12E633E674F571E5 ON hoard (archaeology_context_nature_id)');
$this->addSql('ALTER TABLE hoard_audit ADD archaeology_site_context_detail_id INT DEFAULT NULL, ADD archaeology_context_nature_id INT DEFAULT NULL');
}
}