<?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 Version20191130004128 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_payment RENAME payment');
$this->addSql('CREATE TABLE order_payment (id INT AUTO_INCREMENT NOT NULL, order_id INT DEFAULT NULL, payment_id INT DEFAULT NULL, INDEX IDX_9B522D468D9F6D38 (order_id), UNIQUE INDEX UNIQ_9B522D464C3A3BB (payment_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE order_payment ADD CONSTRAINT FK_9B522D468D9F6D38 FOREIGN KEY (order_id) REFERENCES orders (id)');
$this->addSql('ALTER TABLE order_payment ADD CONSTRAINT FK_9B522D464C3A3BB FOREIGN KEY (payment_id) REFERENCES payment (id)');
$this->addSql('INSERT INTO order_payment(order_id, payment_id) SELECT payment.idOrder, payment.id FROM payment WHERE payment.idOrder IS NOT NULL');
}
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 order_payment');
$this->addSql('ALTER TABLE payment RENAME order_payment');
}
}