migrations/Version20251023174013.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.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20251023174013 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $this->addSql('
  18.             UPDATE tourapp.email_template
  19.             SET variables = COALESCE(variables::jsonb, \'{}\'::jsonb) || 
  20.                 \'{"text_1_agreement": {"description": "Dodatkowa treść umowy", "value": null, "type": "variable"}}\'::jsonb
  21.             WHERE email_template_id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13);
  22.         ');
  23.         $this->addSql('
  24.             UPDATE tourapp.email_template
  25.             SET variables = (
  26.                 SELECT (
  27.                     (SELECT json_object_agg(key, val ORDER BY sort_order, key)
  28.                      FROM (
  29.                          SELECT 
  30.                              key,
  31.                              CASE 
  32.                                  WHEN jsonb_exists(value, \'type\') THEN value
  33.                                  ELSE jsonb_set(value, \'{type}\', \'"variable"\'::jsonb)
  34.                              END AS val,
  35.                              CASE 
  36.                                  WHEN (value->>\'type\') = \'variable\' OR NOT jsonb_exists(value, \'type\') THEN 1
  37.                                  WHEN (value->>\'type\') = \'condition\' THEN 3
  38.                                  ELSE 2
  39.                              END AS sort_order
  40.                          FROM jsonb_each(variables::jsonb)
  41.                      ) s
  42.                     )::json
  43.                 )
  44.             )
  45.             WHERE variables IS NOT NULL
  46.               AND jsonb_typeof(variables::jsonb) = \'object\'
  47.               AND variables::jsonb != \'{}\'::jsonb;
  48.         ');
  49.     }
  50.     public function down(Schema $schema): void
  51.     {
  52.     }
  53. }