<?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 Version20230706061403 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_sponsor ADD main TINYINT(1) DEFAULT 0 NOT NULL');

        $this->addSql('update event
                            inner join event_sponsor
                            on event.id = event_sponsor.event_id
                                and event.main_sponsor_id = event_sponsor.sponsor_id
                        set event_sponsor.main = 1
                    ');

        $this->addSql('ALTER TABLE event DROP FOREIGN KEY FK_3BAE0AA72A0F8F32');
        $this->addSql('DROP INDEX IDX_3BAE0AA72A0F8F32 ON event');
        $this->addSql('ALTER TABLE event DROP main_sponsor_id');
    }

    public function down(Schema $schema): void
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('ALTER TABLE event ADD main_sponsor_id INT DEFAULT NULL');
        $this->addSql('ALTER TABLE event ADD CONSTRAINT FK_3BAE0AA72A0F8F32 FOREIGN KEY (main_sponsor_id) REFERENCES sponsor (id) ON UPDATE NO ACTION ON DELETE NO ACTION');
        $this->addSql('CREATE INDEX IDX_3BAE0AA72A0F8F32 ON event (main_sponsor_id)');

        $this->addSql('update event
                inner join event_sponsor
                on event.id = event_sponsor.event_id
                set event.main_sponsor_id = event_sponsor.sponsor_id
                where event_sponsor.main = 1');

        $this->addSql('ALTER TABLE event_sponsor DROP main');
    }
}
