vendor/bluue/stocks-bundle/migrations/Version20230113104452.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace StocksBundleMigrations;
  4. use DateTime;
  5. use Doctrine\DBAL\Schema\Schema;
  6. use App\Services\ObjectSerialize;
  7. use Symfony\Component\Uid\UuidV6;
  8. use Doctrine\Migrations\AbstractMigration;
  9. final class Version20230113104452 extends AbstractMigration
  10. {
  11.     private ObjectSerialize $objectSerialize;
  12.     public function setObjectSerialize(ObjectSerialize $objectSerialize)
  13.     {
  14.         $this->objectSerialize $objectSerialize;
  15.     }
  16.     public function up(Schema $schema): void
  17.     {
  18.         $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');
  19.         $this->addSql('CREATE INDEX out_of_stock_limit ON stocks_bundle__stock_product_root (out_of_stock_limit)');
  20.         $this->addSql('CREATE INDEX not_send_oos_alert ON stocks_bundle__stock_product_root (not_send_oos_alert)');
  21.     }
  22.     public function postUp(Schema $schema): void
  23.     {
  24.         parent::postUp($schema);
  25.         $this->connection->insert('configuration', [
  26.             'id' => (new UuidV6())->toBinary(),
  27.             'name' => 'stocks_bundle__out_of_stock_limit',
  28.             'context_id' => null,
  29.             'value' => $this->objectSerialize->add((object) ['value' => 0]),
  30.             'created_at' => (new DateTime())->format('Y-m-d H:i:s'),
  31.             'updated_at' => (new DateTime())->format('Y-m-d H:i:s')
  32.         ]);
  33.     }
  34.     public function down(Schema $schema): void
  35.     {
  36.         $this->addSql('DROP INDEX out_of_stock_limit ON stocks_bundle__stock_product_root');
  37.         $this->addSql('DROP INDEX not_send_oos_alert ON stocks_bundle__stock_product_root');
  38.         $this->addSql('ALTER TABLE stocks_bundle__stock_product_root DROP out_of_stock_limit, DROP not_send_oos_alert');
  39.     }
  40. }