app/DoctrineMigrations/Version20251119160834.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_order_itemテーブルの無効なbrother_idを修正
  8.  */
  9. final class Version20251119160834 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'dtb_order_itemテーブルの無効なbrother_id値をNULLに修正';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // 無効なbrother_idをNULLに設定
  18.         // dtb_customer_subテーブルに存在しないbrother_idを持つレコードを修正
  19.         $this->addSql("
  20.             UPDATE dtb_order_item 
  21.             SET brother_id = NULL 
  22.             WHERE brother_id IS NOT NULL 
  23.             AND brother_id NOT IN (SELECT id FROM dtb_customer_sub)
  24.         ");
  25.     }
  26.     public function down(Schema $schema): void
  27.     {
  28.         // このマイグレーションはデータクリーニングのため、ロールバックは不要
  29.         // 無効な値に戻すことは望ましくない
  30.     }
  31. }