migrations/Version20250511082611.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 Version20250511082611 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.travelpay_reckoning t
  19.             SET paymentdetails = sub.new_paymentdetails
  20.             FROM (
  21.                 SELECT
  22.                     id,
  23.                     json_agg(value) AS new_paymentdetails
  24.                 FROM tourapp.travelpay_reckoning,
  25.                      json_each(paymentdetails)
  26.                 WHERE json_typeof(paymentdetails) = \'object\'
  27.                 GROUP BY id
  28.             ) AS sub
  29.             WHERE t.id = sub.id;
  30.         ');
  31.         $this->addSql('
  32.             UPDATE tourapp.travelpay_reckoning t
  33.             SET tripdetails = sub.updated_tripdetails
  34.             FROM (
  35.                 SELECT
  36.                     id,
  37.                     json_agg(
  38.                         jsonb_set(
  39.                             elem,
  40.                             \'{participants_points}\',
  41.                             to_jsonb(
  42.                                 CASE
  43.                                     WHEN (elem->>\'participants_count\')::int > participantsthreshold THEN
  44.                                         CEIL(((elem->>\'participants_count\')::numeric - participantsthreshold) / participantsthreshold) * (elem->>\'points\')::int
  45.                                     ELSE 0
  46.                                 END
  47.                             )
  48.                         )
  49.                     ) AS updated_tripdetails
  50.                 FROM tourapp.travelpay_reckoning,
  51.                      jsonb_array_elements(tripdetails::jsonb) AS elem
  52.                 GROUP BY id
  53.             ) sub
  54.             WHERE t.id = sub.id;
  55.         ');
  56.         $this->addSql('
  57.             UPDATE tourapp.travelpay_reckoning t
  58.             SET tripdetails = sub.updated_tripdetails
  59.             FROM (
  60.                 SELECT
  61.                     id,
  62.                     json_agg(
  63.                         jsonb_set(
  64.                             elem,
  65.                             \'{participants_points}\',
  66.                             to_jsonb(
  67.                                 CASE
  68.                                     WHEN (elem->>\'participants_count\')::int > participantsthreshold THEN
  69.                                         CEIL(((elem->>\'participants_count\')::numeric - participantsthreshold) / participantsthreshold) * (elem->>\'points\')::int
  70.                                     ELSE 0
  71.                                 END
  72.                             )
  73.                         )
  74.                     ) AS updated_tripdetails
  75.                 FROM tourapp.travelpay_reckoning,
  76.                      jsonb_array_elements(tripdetails::jsonb) AS elem
  77.                 GROUP BY id
  78.             ) sub
  79.             WHERE t.id = sub.id;
  80.         ');
  81.         $this->addSql('
  82.             UPDATE tourapp.travelpay_reckoning
  83.             SET fixedamount=0
  84.             WHERE packageid !=1;
  85.         ');
  86.     }
  87.     public function down(Schema $schema): void
  88.     {}
  89. }