migrations/Version20251216160119.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 Version20251216160119 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return "Adds missing translations for categories based on the franchise's Locales.";
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql('
  15.                 INSERT INTO category_translation (
  16.                     category_id,
  17.                     locale_id,
  18.                     name,
  19.                     description,
  20.                     created_at,
  21.                     updated_at
  22.                 )
  23.                 SELECT
  24.                     c.id AS category_id,
  25.                     fl.locale_id,
  26.                     CONCAT("cat_", c.id) AS name,
  27.                     NULL AS description,
  28.                     c.created_at,
  29.                     c.updated_at
  30.                 FROM category c
  31.                 INNER JOIN shop s ON s.id = c.shop_id
  32.                 INNER JOIN franchise f ON f.id = s.franchise_id
  33.                 INNER JOIN franchise_locale fl ON fl.franchise_id = f.id
  34.                 LEFT JOIN category_translation ct
  35.                     ON ct.category_id = c.id
  36.                 WHERE ct.id IS NULL;
  37.         ');
  38.     }
  39. }