<?php
declare(strict_types=1);
namespace StocksBundleMigrations;
use DateTime;
use Doctrine\DBAL\Schema\Schema;
use App\Services\ObjectSerialize;
use Symfony\Component\Uid\UuidV6;
use Doctrine\Migrations\AbstractMigration;
final class Version20230113104452 extends AbstractMigration
{
private ObjectSerialize $objectSerialize;
public function setObjectSerialize(ObjectSerialize $objectSerialize)
{
$this->objectSerialize = $objectSerialize;
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE stocks_bundle__stock_product_root ADD out_of_stock_limit INT DEFAULT NULL, ADD not_send_oos_alert TINYINT(1) DEFAULT 0 NOT NULL');
$this->addSql('CREATE INDEX out_of_stock_limit ON stocks_bundle__stock_product_root (out_of_stock_limit)');
$this->addSql('CREATE INDEX not_send_oos_alert ON stocks_bundle__stock_product_root (not_send_oos_alert)');
}
public function postUp(Schema $schema): void
{
parent::postUp($schema);
$this->connection->insert('configuration', [
'id' => (new UuidV6())->toBinary(),
'name' => 'stocks_bundle__out_of_stock_limit',
'context_id' => null,
'value' => $this->objectSerialize->add((object) ['value' => 0]),
'created_at' => (new DateTime())->format('Y-m-d H:i:s'),
'updated_at' => (new DateTime())->format('Y-m-d H:i:s')
]);
}
public function down(Schema $schema): void
{
$this->addSql('DROP INDEX out_of_stock_limit ON stocks_bundle__stock_product_root');
$this->addSql('DROP INDEX not_send_oos_alert ON stocks_bundle__stock_product_root');
$this->addSql('ALTER TABLE stocks_bundle__stock_product_root DROP out_of_stock_limit, DROP not_send_oos_alert');
}
}