migrations/Version20190520040015.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 Version20190520040015 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('ALTER TABLE order_renegotiation DROP FOREIGN KEY FK_B451F8F3B45791E6');
  20.         $this->addSql('DROP INDEX IDX_B451F8F3B45791E6 ON order_renegotiation');
  21.         $this->addSql('ALTER TABLE order_renegotiation DROP idState');
  22.         $this->addSql('ALTER TABLE orders DROP FOREIGN KEY FK_E52FFDEEB45791E6');
  23.         $this->addSql('DROP INDEX IDX_E52FFDEEB45791E6 ON orders');
  24.         // add our new state field
  25.         $this->addSql('ALTER TABLE orders ADD state VARCHAR(100) NOT NULL');
  26.         // migrate the data to our new state field
  27.         $this->addSql('UPDATE orders JOIN orderStates ON orderStates.id = orders.idState SET state=orderStates.name');
  28.         // drop the old field and table
  29.         $this->addSql('DROP TABLE orderStates');
  30.         $this->addSql('ALTER TABLE orders DROP idState');
  31.     }
  32.     public function down(Schema $schema) : void
  33.     {
  34.         // this down() migration is auto-generated, please modify it to your needs
  35.         $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql''Migration can only be executed safely on \'mysql\'.');
  36.         $this->addSql('CREATE TABLE orderStates (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(40) NOT NULL COLLATE utf8_unicode_ci, description VARCHAR(255) NOT NULL COLLATE utf8_unicode_ci, image VARCHAR(40) NOT NULL COLLATE utf8_unicode_ci, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB COMMENT = \'\' ');
  37.         $this->addSql('ALTER TABLE order_renegotiation ADD idState INT DEFAULT NULL');
  38.         $this->addSql('ALTER TABLE order_renegotiation ADD CONSTRAINT FK_B451F8F3B45791E6 FOREIGN KEY (idState) REFERENCES orderStates (id)');
  39.         $this->addSql('CREATE INDEX IDX_B451F8F3B45791E6 ON order_renegotiation (idState)');
  40.         $this->addSql('ALTER TABLE orders DROP FOREIGN KEY FK_E52FFDEEC6B1F05C');
  41.         $this->addSql('DROP INDEX IDX_E52FFDEEC6B1F05C ON orders');
  42.         $this->addSql('ALTER TABLE orders ADD idState INT DEFAULT NULL, DROP state');
  43.         $this->addSql('ALTER TABLE orders ADD CONSTRAINT FK_E52FFDEEB45791E6 FOREIGN KEY (idState) REFERENCES orderStates (id)');
  44.         $this->addSql('CREATE INDEX IDX_E52FFDEEB45791E6 ON orders (idState)');
  45.     }
  46. }