<?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 Version20210107070954 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->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE reservation ADD lot_id INT DEFAULT NULL');
$this->addSql('update reservation set lot_id = (SELECT lot.id FROM lot, planning WHERE lot.aquereur_id = reservation.user_id AND planning.id= reservation.planning_id AND planning.programme_id = lot.programme_id )');
$this->addSql('ALTER TABLE reservation ADD CONSTRAINT FK_42C84955A8CBA5F7 FOREIGN KEY (lot_id) REFERENCES lot (id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_42C84955A8CBA5F7 ON reservation (lot_id)');
$this->addSql('ALTER TABLE programme CHANGE user_id user_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE reservation CHANGE lot_id lot_id INT NOT NULL');
$this->addSql('ALTER TABLE planning DROP INDEX UNIQ_D499BFF662BB7AEE, ADD INDEX IDX_D499BFF662BB7AEE (programme_id)');
$this->addSql('ALTER TABLE planning ADD name VARCHAR(255) NOT NULL, ADD close TINYINT(1) NOT NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE planning DROP INDEX IDX_D499BFF662BB7AEE, ADD UNIQUE INDEX UNIQ_D499BFF662BB7AEE (programme_id)');
$this->addSql('ALTER TABLE planning DROP name, DROP close');
$this->addSql('ALTER TABLE programme CHANGE user_id user_id INT NOT NULL');
$this->addSql('ALTER TABLE reservation CHANGE lot_id lot_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE reservation DROP FOREIGN KEY FK_42C84955A8CBA5F7');
$this->addSql('DROP INDEX UNIQ_42C84955A8CBA5F7 ON reservation');
$this->addSql('ALTER TABLE reservation DROP lot_id');
}
}