<?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 Version20190808131024 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 booking_resource (booking_id INT NOT NULL, resource_id INT NOT NULL, INDEX IDX_87A56A9B3301C60 (booking_id), INDEX IDX_87A56A9B89329D25 (resource_id), PRIMARY KEY(booking_id, resource_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
$this->addSql('ALTER TABLE booking_resource ADD CONSTRAINT FK_87A56A9B3301C60 FOREIGN KEY (booking_id) REFERENCES booking (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE booking_resource ADD CONSTRAINT FK_87A56A9B89329D25 FOREIGN KEY (resource_id) REFERENCES resource (id) ON DELETE CASCADE');
$this->addSql('INSERT INTO booking_resource(booking_id, resource_id) SELECT id,resource_id FROM booking');
$this->addSql('ALTER TABLE booking DROP FOREIGN KEY FK_E00CEDDE89329D25');
$this->addSql('DROP INDEX IDX_E00CEDDE89329D25 ON booking');
$this->addSql('ALTER TABLE booking DROP resource_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 booking ADD resource_id INT NOT NULL');
$this->addSql('ALTER TABLE booking ADD CONSTRAINT FK_E00CEDDE89329D25 FOREIGN KEY (resource_id) REFERENCES resource (id)');
$this->addSql('CREATE INDEX IDX_E00CEDDE89329D25 ON booking (resource_id)');
$this->addSql('UPDATE booking SET booking.resource_id = booking_resource.resource_id FROM booking INNER JOIN booking_resource ON booking.id = booking_resource.booking_id ');
$this->addSql('DROP TABLE booking_resource');
}
}