<?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 Version20170119152907 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_country (hoard_id INT NOT NULL, country_id INT NOT NULL, INDEX IDX_2132874F762C4B4D (hoard_id), INDEX IDX_2132874FF92F3E70 (country_id), PRIMARY KEY(hoard_id, country_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
$this->addSql('ALTER TABLE hoard_country ADD CONSTRAINT FK_2132874F762C4B4D FOREIGN KEY (hoard_id) REFERENCES hoard (id)');
$this->addSql('ALTER TABLE hoard_country ADD CONSTRAINT FK_2132874FF92F3E70 FOREIGN KEY (country_id) REFERENCES country (id)');
$this->addSql('SET FOREIGN_KEY_CHECKS=0');
$this->addSql('INSERT INTO hoard_country (hoard_id, country_id) SELECT id, country_id FROM `hoard`');
$this->addSql('SET FOREIGN_KEY_CHECKS=1');
$this->addSql('INSERT INTO country(id, country) VALUES (100, \'United Kingdom\')');
// 13: England, 34: Northern Ireland, 39: Scotland, 52: Wales
$this->addSql('INSERT INTO hoard_country( hoard_id, country_id ) SELECT id, 100 FROM `hoard` WHERE hoard.country_id IN ( 13, 34, 39, 52 )');
}
/**
* @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_country');
}
}