<?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 Version20201005163248 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('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE project_comment DROP FOREIGN KEY FK_26A5E09126F525E');
$this->addSql('ALTER TABLE project_comment ADD project_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE project_comment ADD CONSTRAINT FK_26A5E09166D1F9C FOREIGN KEY (project_id) REFERENCES project (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE project_comment ADD CONSTRAINT FK_26A5E09126F525E FOREIGN KEY (item_id) REFERENCES project_item (id) ON DELETE SET NULL');
$this->addSql('CREATE INDEX IDX_26A5E09166D1F9C ON project_comment (project_id)');
$this->addSql('UPDATE project_comment pc SET pc.project_id = (SELECT pi.project_id FROM project_item pi WHERE pi.id = pc.item_id LIMIT 1)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE project_comment DROP FOREIGN KEY FK_26A5E09166D1F9C');
$this->addSql('ALTER TABLE project_comment DROP FOREIGN KEY FK_26A5E09126F525E');
$this->addSql('DROP INDEX IDX_26A5E09166D1F9C ON project_comment');
$this->addSql('ALTER TABLE project_comment DROP project_id');
$this->addSql('ALTER TABLE project_comment ADD CONSTRAINT FK_26A5E09126F525E FOREIGN KEY (item_id) REFERENCES project_item (id) ON DELETE CASCADE');
}
}