<?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 Version20220401073413 extends AbstractMigration
{
public function getDescription(): string
{
return 'set Creative as Contractor in Project with null contractor_id. Set contractor_id not nullable';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('UPDATE project SET contractor_id = (SELECT id FROM contractor WHERE short_name = \'Creative\') WHERE contractor_id IS NULL');
$this->addSql('ALTER TABLE project DROP CONSTRAINT FK_2FB3D0EEB0265DC7');
$this->addSql('ALTER TABLE project ALTER contractor_id SET NOT NULL');
$this->addSql('ALTER TABLE project ADD CONSTRAINT FK_2FB3D0EEB0265DC7 FOREIGN KEY (contractor_id) REFERENCES contractor (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE project DROP CONSTRAINT fk_2fb3d0eeb0265dc7');
$this->addSql('ALTER TABLE project ALTER contractor_id DROP NOT NULL');
$this->addSql('ALTER TABLE project ADD CONSTRAINT fk_2fb3d0eeb0265dc7 FOREIGN KEY (contractor_id) REFERENCES contractor (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
}
}