migrations/Version20190808131024.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20190808131024 extends AbstractMigration
  10. {
  11.     public function getDescription() : string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema) : void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql''Migration can only be executed safely on \'mysql\'.');
  19.         $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');
  20.         $this->addSql('ALTER TABLE booking_resource ADD CONSTRAINT FK_87A56A9B3301C60 FOREIGN KEY (booking_id) REFERENCES booking (id) ON DELETE CASCADE');
  21.         $this->addSql('ALTER TABLE booking_resource ADD CONSTRAINT FK_87A56A9B89329D25 FOREIGN KEY (resource_id) REFERENCES resource (id) ON DELETE CASCADE');
  22.         $this->addSql('INSERT INTO booking_resource(booking_id, resource_id) SELECT id,resource_id FROM booking');
  23.         $this->addSql('ALTER TABLE booking DROP FOREIGN KEY FK_E00CEDDE89329D25');
  24.         $this->addSql('DROP INDEX IDX_E00CEDDE89329D25 ON booking');
  25.         $this->addSql('ALTER TABLE booking DROP resource_id');
  26.     }
  27.     public function down(Schema $schema) : void
  28.     {
  29.         // this down() migration is auto-generated, please modify it to your needs
  30.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql''Migration can only be executed safely on \'mysql\'.');
  31.         $this->addSql('ALTER TABLE booking ADD resource_id INT NOT NULL');
  32.         $this->addSql('ALTER TABLE booking ADD CONSTRAINT FK_E00CEDDE89329D25 FOREIGN KEY (resource_id) REFERENCES resource (id)');
  33.         $this->addSql('CREATE INDEX IDX_E00CEDDE89329D25 ON booking (resource_id)');
  34.         $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 ');
  35.         $this->addSql('DROP TABLE booking_resource');
  36.     }
  37. }