<?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 Version20231110134535 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('ALTER TABLE event ADD payment_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE event ADD CONSTRAINT FK_3BAE0AA74C3A3BB FOREIGN KEY (payment_id) REFERENCES payment (id)');
$this->addSql('CREATE INDEX IDX_3BAE0AA74C3A3BB ON event (payment_id)');
$this->addSql(
'INSERT INTO `event` (payment_id, checking_id, user_id, status, created_at, updated_at)
SELECT payment.id, payment.checking_id, `order`.customer_id, payment.state, payment.updated_at, payment.updated_at
FROM `payment`
JOIN `order` ON `payment`.checking_id = `order`.id
JOIN `payment_method` ON `payment`.payment_method_id = `payment_method`.id
JOIN `payment_method_config` ON `payment_method`.payemnt_menthod_config_id = `payment_method_config`.id
WHERE NOT EXISTS (
SELECT 1 FROM event
WHERE event.payment_id = payment.id
) AND `payment_method_config`.type = "online" AND payment.state != "new"'
);
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE event DROP FOREIGN KEY FK_3BAE0AA74C3A3BB');
$this->addSql('DROP INDEX IDX_3BAE0AA74C3A3BB ON event');
$this->addSql('ALTER TABLE event DROP payment_id');
}
}