<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260401120000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add partial quantity support: stock.allow_partial_quantities, stock_item.quantity, stock_transaction.quantity to decimal';
}
public function up(Schema $schema): void
{
$stockTable = $schema->getTable('stock');
if (!$stockTable->hasColumn('allow_partial_quantities')) {
$this->addSql('ALTER TABLE stock ADD allow_partial_quantities TINYINT(1) NOT NULL DEFAULT 0');
}
$stockItemTable = $schema->getTable('stock_item');
if (!$stockItemTable->hasColumn('quantity')) {
$this->addSql("ALTER TABLE stock_item ADD quantity DECIMAL(8,2) NOT NULL DEFAULT '1.00'");
}
$this->addSql('ALTER TABLE stock_transaction MODIFY quantity DECIMAL(8,2) NOT NULL');
}
public function down(Schema $schema): void
{
$stockTable = $schema->getTable('stock');
if ($stockTable->hasColumn('allow_partial_quantities')) {
$this->addSql('ALTER TABLE stock DROP allow_partial_quantities');
}
$stockItemTable = $schema->getTable('stock_item');
if ($stockItemTable->hasColumn('quantity')) {
$this->addSql('ALTER TABLE stock_item DROP quantity');
}
$this->addSql('ALTER TABLE stock_transaction MODIFY quantity INT NOT NULL');
}
}