<?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 Version20230927094838 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('
CREATE FUNCTION getCurrentPrice(productId INT) RETURNS INT
BEGIN
DECLARE vPrice INT;
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;
RETURN vPrice;
END;
DELIMITER ;
');
$this->addSql('
CREATE FUNCTION getPreviousPrice(productId INT) RETURNS INT
BEGIN
DECLARE vPrice INT;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vPrice = NULL;
SELECT purchase_price INTO vPrice FROM shop_price pr WHERE pr.product_id = productId
ORDER BY pr.created_at DESC LIMIT 1,1;
RETURN vPrice;
END;
DELIMITER ;
');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP FUNCTION IF EXISTS getCurrentPrice');
$this->addSql('DROP FUNCTION IF EXISTS getPreviousPrice');
}
}