migrations/Version20260316095211.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. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  7. use Symfony\Component\DependencyInjection\ContainerAwareTrait;
  8. final class Version20260316095211 extends AbstractMigration implements ContainerAwareInterface
  9. {
  10.     use ContainerAwareTrait;
  11.     public function getDescription(): string
  12.     {
  13.         return 'Sync SKU with External ID for KROUSTY franchise (Prod only).';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $env $this->container->get('kernel')->getEnvironment();
  18.         if ($env === 'prod') {
  19.             $this->addSql("
  20.                 UPDATE product p
  21.                 INNER JOIN shop s ON p.shop_id = s.id
  22.                 INNER JOIN franchise f ON s.franchise_id = f.id
  23.                 SET p.sku = p.external_id
  24.                 WHERE f.name LIKE '%KROUSTY%'
  25.                   AND p.external_id IS NOT NULL 
  26.                   AND p.external_id <> ''
  27.             ");
  28.         } else {
  29.             $this->write("Skipping SKU sync: Environment is '$env' (not 'prod').");
  30.         }
  31.     }
  32. }