app/DoctrineMigrations/Version20251224190612.php line 1

Open in your IDE?
  1. <?php
    
    declare(strict_types=1);
    
    namespace DoctrineMigrations;
    
    use Doctrine\DBAL\Schema\Schema;
    use Doctrine\Migrations\AbstractMigration;
    
    /**
     * OrderRegisterItemテーブルにdel_flgカラムを追加
     */
    final class Version20251224190612 extends AbstractMigration
    {
        public function up(Schema $schema): void
        {
            // テーブルの存在確認
            if (!$schema->hasTable('dtb_order_register_item')) {
                return;
            }
    
            $table = $schema->getTable('dtb_order_register_item');
    
            // カラムが存在しない場合のみ追加
            if (!$table->hasColumn('del_flg')) {
                $this->addSql("ALTER TABLE dtb_order_register_item ADD del_flg SMALLINT DEFAULT 0 NOT NULL");
            }
        }
    
        public function down(Schema $schema): void
        {
            // テーブルの存在確認
            if (!$schema->hasTable('dtb_order_register_item')) {
                return;
            }
    
            $table = $schema->getTable('dtb_order_register_item');
    
            // カラムが存在する場合のみ削除
            if ($table->hasColumn('del_flg')) {
                $this->addSql("ALTER TABLE dtb_order_register_item DROP COLUMN del_flg");
            }
        }
    }