<?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 Version20230120135636 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE affboss_affjuniors (user_source INT NOT NULL, user_target INT NOT NULL, INDEX IDX_DA8D67573AD8644E (user_source), INDEX IDX_DA8D6757233D34C1 (user_target), PRIMARY KEY(user_source, user_target)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE affboss_affjuniors ADD CONSTRAINT FK_DA8D67573AD8644E FOREIGN KEY (user_source) REFERENCES user (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE affboss_affjuniors ADD CONSTRAINT FK_DA8D6757233D34C1 FOREIGN KEY (user_target) REFERENCES user (id) ON DELETE CASCADE');
$this->addSql('INSERT INTO affboss_affjuniors SELECT aff_boss_id, id FROM user WHERE aff_boss_id IS NOT NULL');
$this->addSql('ALTER TABLE user DROP FOREIGN KEY FK_8D93D6493E28FC6B');
$this->addSql('DROP INDEX IDX_8D93D6493E28FC6B ON user');
$this->addSql('ALTER TABLE user DROP aff_boss_id');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE affboss_affjuniors DROP FOREIGN KEY FK_DA8D67573AD8644E');
$this->addSql('ALTER TABLE affboss_affjuniors DROP FOREIGN KEY FK_DA8D6757233D34C1');
//$this->addSql('DROP TABLE affboss_affjuniors');
$this->addSql('ALTER TABLE user ADD aff_boss_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE user ADD CONSTRAINT FK_8D93D6493E28FC6B FOREIGN KEY (aff_boss_id) REFERENCES user (id)');
$this->addSql('CREATE INDEX IDX_8D93D6493E28FC6B ON user (aff_boss_id)');
}
}