app/DoctrineMigrations/Version20260203000000.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. /**
  7.  * 商品規格に仕入単価カラムを追加
  8.  */
  9. final class Version20260203000000 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '商品規格テーブルに仕入単価カラムを追加';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // カラムの存在チェック
  18.         if ($schema->hasTable('dtb_product_class')) {
  19.             $table $schema->getTable('dtb_product_class');
  20.             
  21.             // purchase_price カラムが存在しない場合のみ追加
  22.             if (!$table->hasColumn('purchase_price')) {
  23.                 $this->addSql('ALTER TABLE dtb_product_class ADD COLUMN purchase_price DECIMAL(12, 2) DEFAULT NULL');
  24.             }
  25.         }
  26.     }
  27.     public function down(Schema $schema): void
  28.     {
  29.         // カラムの存在チェック
  30.         if ($schema->hasTable('dtb_product_class')) {
  31.             $table $schema->getTable('dtb_product_class');
  32.             
  33.             // purchase_price カラムが存在する場合のみ削除
  34.             if ($table->hasColumn('purchase_price')) {
  35.                 $this->addSql('ALTER TABLE dtb_product_class DROP COLUMN purchase_price');
  36.             }
  37.         }
  38.     }
  39. }