migrations/Version20231110134535.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 Version20231110134535 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('ALTER TABLE event ADD payment_id INT DEFAULT NULL');
  19.         $this->addSql('ALTER TABLE event ADD CONSTRAINT FK_3BAE0AA74C3A3BB FOREIGN KEY (payment_id) REFERENCES payment (id)');
  20.         $this->addSql('CREATE INDEX IDX_3BAE0AA74C3A3BB ON event (payment_id)');
  21.         $this->addSql(
  22.             'INSERT INTO `event` (payment_id, checking_id, user_id, status, created_at, updated_at)
  23.             SELECT payment.id, payment.checking_id, `order`.customer_id, payment.state, payment.updated_at, payment.updated_at
  24.             FROM `payment`
  25.             JOIN `order` ON `payment`.checking_id = `order`.id
  26.             JOIN `payment_method` ON `payment`.payment_method_id = `payment_method`.id
  27.             JOIN `payment_method_config` ON `payment_method`.payemnt_menthod_config_id = `payment_method_config`.id
  28.             WHERE NOT EXISTS (
  29.                 SELECT 1 FROM event 
  30.                 WHERE event.payment_id = payment.id
  31.             ) AND `payment_method_config`.type = "online" AND payment.state != "new"'
  32.         );
  33.     }
  34.     public function down(Schema $schema): void
  35.     {
  36.         // this down() migration is auto-generated, please modify it to your needs
  37.         $this->addSql('ALTER TABLE event DROP FOREIGN KEY FK_3BAE0AA74C3A3BB');
  38.         $this->addSql('DROP INDEX IDX_3BAE0AA74C3A3BB ON event');
  39.         $this->addSql('ALTER TABLE event DROP payment_id');
  40.     }
  41. }