<?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 Version20250511082611 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
$this->addSql('
UPDATE tourapp.travelpay_reckoning t
SET paymentdetails = sub.new_paymentdetails
FROM (
SELECT
id,
json_agg(value) AS new_paymentdetails
FROM tourapp.travelpay_reckoning,
json_each(paymentdetails)
WHERE json_typeof(paymentdetails) = \'object\'
GROUP BY id
) AS sub
WHERE t.id = sub.id;
');
$this->addSql('
UPDATE tourapp.travelpay_reckoning t
SET tripdetails = sub.updated_tripdetails
FROM (
SELECT
id,
json_agg(
jsonb_set(
elem,
\'{participants_points}\',
to_jsonb(
CASE
WHEN (elem->>\'participants_count\')::int > participantsthreshold THEN
CEIL(((elem->>\'participants_count\')::numeric - participantsthreshold) / participantsthreshold) * (elem->>\'points\')::int
ELSE 0
END
)
)
) AS updated_tripdetails
FROM tourapp.travelpay_reckoning,
jsonb_array_elements(tripdetails::jsonb) AS elem
GROUP BY id
) sub
WHERE t.id = sub.id;
');
$this->addSql('
UPDATE tourapp.travelpay_reckoning t
SET tripdetails = sub.updated_tripdetails
FROM (
SELECT
id,
json_agg(
jsonb_set(
elem,
\'{participants_points}\',
to_jsonb(
CASE
WHEN (elem->>\'participants_count\')::int > participantsthreshold THEN
CEIL(((elem->>\'participants_count\')::numeric - participantsthreshold) / participantsthreshold) * (elem->>\'points\')::int
ELSE 0
END
)
)
) AS updated_tripdetails
FROM tourapp.travelpay_reckoning,
jsonb_array_elements(tripdetails::jsonb) AS elem
GROUP BY id
) sub
WHERE t.id = sub.id;
');
$this->addSql('
UPDATE tourapp.travelpay_reckoning
SET fixedamount=0
WHERE packageid !=1;
');
}
public function down(Schema $schema): void
{}
}