<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20251023174013 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
$this->addSql('
UPDATE tourapp.email_template
SET variables = COALESCE(variables::jsonb, \'{}\'::jsonb) ||
\'{"text_1_agreement": {"description": "Dodatkowa treść umowy", "value": null, "type": "variable"}}\'::jsonb
WHERE email_template_id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13);
');
$this->addSql('
UPDATE tourapp.email_template
SET variables = (
SELECT (
(SELECT json_object_agg(key, val ORDER BY sort_order, key)
FROM (
SELECT
key,
CASE
WHEN jsonb_exists(value, \'type\') THEN value
ELSE jsonb_set(value, \'{type}\', \'"variable"\'::jsonb)
END AS val,
CASE
WHEN (value->>\'type\') = \'variable\' OR NOT jsonb_exists(value, \'type\') THEN 1
WHEN (value->>\'type\') = \'condition\' THEN 3
ELSE 2
END AS sort_order
FROM jsonb_each(variables::jsonb)
) s
)::json
)
)
WHERE variables IS NOT NULL
AND jsonb_typeof(variables::jsonb) = \'object\'
AND variables::jsonb != \'{}\'::jsonb;
');
}
public function down(Schema $schema): void
{
}
}