<?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 Version20210127044204 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_item ADD tax NUMERIC(10, 2) NOT NULL, ADD base_price NUMERIC(10, 4) NOT NULL');
$this->addSql('ALTER TABLE order_item CHANGE price price NUMERIC(10, 2) NOT NULL');
$this->addSql('UPDATE order_item LEFT JOIN product ON order_item.product_id = product.id SET order_item.tax=product.tax, order_item.base_price=ROUND(order_item.price/(1 + product.tax/100), 4)');
}
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 order_item CHANGE price price DOUBLE PRECISION NOT NULL');
$this->addSql('ALTER TABLE order_item DROP tax, DROP base_price');
}
}