app/DoctrineMigrations/Version20251119160834.php line 1

Open in your IDE?
  1. <?php
    
    declare(strict_types=1);
    
    namespace DoctrineMigrations;
    
    use Doctrine\DBAL\Schema\Schema;
    use Doctrine\Migrations\AbstractMigration;
    
    /**
     * dtb_order_itemテーブルの無効なbrother_idを修正
     */
    final class Version20251119160834 extends AbstractMigration
    {
        public function getDescription(): string
        {
            return 'dtb_order_itemテーブルの無効なbrother_id値をNULLに修正';
        }
    
        public function up(Schema $schema): void
        {
            // 無効なbrother_idをNULLに設定
            // dtb_customer_subテーブルに存在しないbrother_idを持つレコードを修正
            $this->addSql("
                UPDATE dtb_order_item 
                SET brother_id = NULL 
                WHERE brother_id IS NOT NULL 
                AND brother_id NOT IN (SELECT id FROM dtb_customer_sub)
            ");
        }
    
        public function down(Schema $schema): void
        {
            // このマイグレーションはデータクリーニングのため、ロールバックは不要
            // 無効な値に戻すことは望ましくない
        }
    }