app/DoctrineMigrations/Version20260203000000.php line 1

Open in your IDE?
  1. <?php
    
    declare(strict_types=1);
    
    namespace DoctrineMigrations;
    
    use Doctrine\DBAL\Schema\Schema;
    use Doctrine\Migrations\AbstractMigration;
    
    /**
     * 商品規格に仕入単価カラムを追加
     */
    final class Version20260203000000 extends AbstractMigration
    {
        public function getDescription(): string
        {
            return '商品規格テーブルに仕入単価カラムを追加';
        }
    
        public function up(Schema $schema): void
        {
            // カラムの存在チェック
            if ($schema->hasTable('dtb_product_class')) {
                $table = $schema->getTable('dtb_product_class');
                
                // purchase_price カラムが存在しない場合のみ追加
                if (!$table->hasColumn('purchase_price')) {
                    $this->addSql('ALTER TABLE dtb_product_class ADD COLUMN purchase_price DECIMAL(12, 2) DEFAULT NULL');
                }
            }
        }
    
        public function down(Schema $schema): void
        {
            // カラムの存在チェック
            if ($schema->hasTable('dtb_product_class')) {
                $table = $schema->getTable('dtb_product_class');
                
                // purchase_price カラムが存在する場合のみ削除
                if ($table->hasColumn('purchase_price')) {
                    $this->addSql('ALTER TABLE dtb_product_class DROP COLUMN purchase_price');
                }
            }
        }
    }