migrations/Version20230927094838.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 Version20230927094838 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $this->addSql('
  19.             CREATE FUNCTION getCurrentPrice(productId INT) RETURNS INT
  20.             BEGIN
  21.                 DECLARE vPrice INT;
  22.                 SELECT purchase_price INTO vPrice FROM shop_product p INNER JOIN shop_price pr ON p.current_price_id = pr.id WHERE p.ID = productId;
  23.                 RETURN vPrice;
  24.             END;
  25.             DELIMITER ;
  26.         ');
  27.         $this->addSql('
  28.             CREATE FUNCTION getPreviousPrice(productId INT) RETURNS INT
  29.             BEGIN
  30.                 DECLARE vPrice INT;
  31.                 DECLARE CONTINUE HANDLER FOR NOT FOUND SET vPrice = NULL;
  32.                 SELECT purchase_price INTO vPrice FROM shop_price pr  WHERE pr.product_id = productId
  33.                 ORDER BY pr.created_at DESC LIMIT 1,1;
  34.                 RETURN vPrice;
  35.             END;
  36.             DELIMITER ;
  37.         ');
  38.     }
  39.     public function down(Schema $schema): void
  40.     {
  41.         // this down() migration is auto-generated, please modify it to your needs
  42.         $this->addSql('DROP FUNCTION IF EXISTS getCurrentPrice');
  43.         $this->addSql('DROP FUNCTION IF EXISTS getPreviousPrice');
  44.     }
  45. }