app/DoctrineMigrations/Version20251119161129.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.  * dtb_productテーブルの各種フラグカラムのNULL値を修正
  8.  */
  9. final class Version20251119161129 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'dtb_productテーブルのsales_period_flg, ship_free_flg, no_returnカラムのNULL値をデフォルト値に修正';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // sales_period_flgのNULL値を0に設定
  18.         $this->addSql("UPDATE dtb_product SET sales_period_flg = 0 WHERE sales_period_flg IS NULL");
  19.         
  20.         // ship_free_flgのNULL値を0に設定
  21.         $this->addSql("UPDATE dtb_product SET ship_free_flg = 0 WHERE ship_free_flg IS NULL");
  22.         
  23.         // no_returnのNULL値を0に設定
  24.         $this->addSql("UPDATE dtb_product SET no_return = 0 WHERE no_return IS NULL");
  25.     }
  26.     public function down(Schema $schema): void
  27.     {
  28.         // このマイグレーションはデータクリーニングのため、ロールバックは不要
  29.         // NULL値に戻すことは望ましくない
  30.     }
  31. }