migrations/Version20260401120000.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. final class Version20260401120000 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Add partial quantity support: stock.allow_partial_quantities, stock_item.quantity, stock_transaction.quantity to decimal';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $stockTable $schema->getTable('stock');
  15.         if (!$stockTable->hasColumn('allow_partial_quantities')) {
  16.             $this->addSql('ALTER TABLE stock ADD allow_partial_quantities TINYINT(1) NOT NULL DEFAULT 0');
  17.         }
  18.         $stockItemTable $schema->getTable('stock_item');
  19.         if (!$stockItemTable->hasColumn('quantity')) {
  20.             $this->addSql("ALTER TABLE stock_item ADD quantity DECIMAL(8,2) NOT NULL DEFAULT '1.00'");
  21.         }
  22.         $this->addSql('ALTER TABLE stock_transaction MODIFY quantity DECIMAL(8,2) NOT NULL');
  23.     }
  24.     public function down(Schema $schema): void
  25.     {
  26.         $stockTable $schema->getTable('stock');
  27.         if ($stockTable->hasColumn('allow_partial_quantities')) {
  28.             $this->addSql('ALTER TABLE stock DROP allow_partial_quantities');
  29.         }
  30.         $stockItemTable $schema->getTable('stock_item');
  31.         if ($stockItemTable->hasColumn('quantity')) {
  32.             $this->addSql('ALTER TABLE stock_item DROP quantity');
  33.         }
  34.         $this->addSql('ALTER TABLE stock_transaction MODIFY quantity INT NOT NULL');
  35.     }
  36. }