app/DoctrineMigrations/Version20251224190612.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.  * OrderRegisterItemテーブルにdel_flgカラムを追加
  8.  */
  9. final class Version20251224190612 extends AbstractMigration
  10. {
  11.     public function up(Schema $schema): void
  12.     {
  13.         // テーブルの存在確認
  14.         if (!$schema->hasTable('dtb_order_register_item')) {
  15.             return;
  16.         }
  17.         $table $schema->getTable('dtb_order_register_item');
  18.         // カラムが存在しない場合のみ追加
  19.         if (!$table->hasColumn('del_flg')) {
  20.             $this->addSql("ALTER TABLE dtb_order_register_item ADD del_flg SMALLINT DEFAULT 0 NOT NULL");
  21.         }
  22.     }
  23.     public function down(Schema $schema): void
  24.     {
  25.         // テーブルの存在確認
  26.         if (!$schema->hasTable('dtb_order_register_item')) {
  27.             return;
  28.         }
  29.         $table $schema->getTable('dtb_order_register_item');
  30.         // カラムが存在する場合のみ削除
  31.         if ($table->hasColumn('del_flg')) {
  32.             $this->addSql("ALTER TABLE dtb_order_register_item DROP COLUMN del_flg");
  33.         }
  34.     }
  35. }