migrations/Version20231228120024.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 Version20231228120024 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // Some values may be incorrectly inserted if the prices of certain products or the rates of certain taxes have been changed after the creation of the orders.
  18.         $this->addSql('DELETE FROM `doctrine_migration_versions` WHERE `version` LIKE "%Version20231220155042"');
  19.         $this->addSql('UPDATE order_item oi
  20.             JOIN product p ON oi.product_id = p.id
  21.             JOIN `order` o ON oi.checking_id = o.id
  22.             JOIN shop_mode sm ON o.shop_mode_id = sm.id
  23.             JOIN product_shop_mode psm ON p.id = psm.product_id AND psm.shop_mode_id = sm.id
  24.             JOIN tax t ON psm.tax_id = t.id
  25.             SET oi.taxes_total = ROUND(
  26.                 (oi.total - (oi.total / (1 + t.rate))) * oi.quantity, 2
  27.             )');
  28.         $this->addSql('UPDATE `order` o
  29.                    SET o.taxes_total = (
  30.                        SELECT SUM(oi.taxes_total)
  31.                        FROM order_item oi
  32.                        WHERE oi.checking_id = o.id
  33.                    )');
  34.     }
  35.     public function down(Schema $schema): void
  36.     {
  37.         // this down() migration is auto-generated, please modify it to your needs
  38.     }
  39. }