<?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 Version20240213150008 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->addSql('ALTER TABLE product ADD sku VARCHAR(255) NOT NULL');
$products = $this->connection->fetchAllAssociative('SELECT id FROM product');
foreach ($products as $product) {
$this->addSql(
'UPDATE product SET sku = :sku WHERE id = :id',
[
'sku' => strtoupper(uniqid('FOX_')),
'id' => $product['id'],
]
);
}
$this->addSql('ALTER TABLE order_item ADD free TINYINT(1) DEFAULT 0 NOT NULL');
$this->addSql('ALTER TABLE order_item ADD external_reference VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE `order` CHANGE items_total items_total INT NOT NULL, CHANGE total total INT NOT NULL');
$this->addSql('ALTER TABLE order_item CHANGE total total INT NOT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE product DROP sku');
$this->addSql('ALTER TABLE order_item DROP free');
$this->addSql('ALTER TABLE order_item DROP external_reference');
$this->addSql('ALTER TABLE `order` CHANGE items_total items_total DOUBLE PRECISION NOT NULL, CHANGE total total DOUBLE PRECISION NOT NULL');
$this->addSql('ALTER TABLE order_item CHANGE total total DOUBLE PRECISION NOT NULL');
}
}