<?php
declare(strict_types=1);
namespace Boldr\Shop\ShopBundle\Migrations;
use Doctrine\DBAL\Schema\Schema;
use Boldr\Cms\CmsBundle\BoldrCmsMigration;
final class Version1_15_4 extends BoldrCmsMigration
{
public function getBundle(): string { return 'boldr/shop-bundle'; }
public function getVersion(): ?string { return '1.15.4'; }
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE shop_order ADD item_count INT UNSIGNED NOT NULL, ADD total_price DOUBLE PRECISION NULL');
$this->addSql('UPDATE shop_order o SET o.item_count = (SELECT COALESCE(SUM(oi.quantity), 0) FROM shop_order_item oi WHERE oi.order_id = o.id), o.total_price = (SELECT SUM(oii.total_price) FROM shop_invoice_item oii WHERE oii.order_id = o.id)');
$this->addSql('CREATE INDEX idx_state ON shop_order (state)');
}
}