migrations/Version20250212104225.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. final class Version20250212104225 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Delete productShopModes if shopMode is disabled & delete productShopModes if shopMode or product is null';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         if ('prod' === $_SERVER['APP_SERVER']) {
  15.             $this->addSql('DELETE FROM `product_shop_mode` WHERE `shop_mode_id` IS NULL OR `product_id` IS NULL');
  16.             $this->addSql('UPDATE product_shop_mode psm 
  17.                 JOIN shop_mode sm ON psm.shop_mode_id = sm.id 
  18.                 SET psm.deleted = true, psm.deleted_at = NOW() 
  19.                 WHERE sm.enabled = false AND psm.deleted = false');
  20.         }
  21.     }
  22. }