<?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 Version20190520040015 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('ALTER TABLE order_renegotiation DROP FOREIGN KEY FK_B451F8F3B45791E6');
$this->addSql('DROP INDEX IDX_B451F8F3B45791E6 ON order_renegotiation');
$this->addSql('ALTER TABLE order_renegotiation DROP idState');
$this->addSql('ALTER TABLE orders DROP FOREIGN KEY FK_E52FFDEEB45791E6');
$this->addSql('DROP INDEX IDX_E52FFDEEB45791E6 ON orders');
// add our new state field
$this->addSql('ALTER TABLE orders ADD state VARCHAR(100) NOT NULL');
// migrate the data to our new state field
$this->addSql('UPDATE orders JOIN orderStates ON orderStates.id = orders.idState SET state=orderStates.name');
// drop the old field and table
$this->addSql('DROP TABLE orderStates');
$this->addSql('ALTER TABLE orders DROP idState');
}
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('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 = \'\' ');
$this->addSql('ALTER TABLE order_renegotiation ADD idState INT DEFAULT NULL');
$this->addSql('ALTER TABLE order_renegotiation ADD CONSTRAINT FK_B451F8F3B45791E6 FOREIGN KEY (idState) REFERENCES orderStates (id)');
$this->addSql('CREATE INDEX IDX_B451F8F3B45791E6 ON order_renegotiation (idState)');
$this->addSql('ALTER TABLE orders DROP FOREIGN KEY FK_E52FFDEEC6B1F05C');
$this->addSql('DROP INDEX IDX_E52FFDEEC6B1F05C ON orders');
$this->addSql('ALTER TABLE orders ADD idState INT DEFAULT NULL, DROP state');
$this->addSql('ALTER TABLE orders ADD CONSTRAINT FK_E52FFDEEB45791E6 FOREIGN KEY (idState) REFERENCES orderStates (id)');
$this->addSql('CREATE INDEX IDX_E52FFDEEB45791E6 ON orders (idState)');
}
}