migrations/Version20220401073413.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20220401073413 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'set Creative as Contractor in Project with null contractor_id. Set contractor_id not nullable';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $this->addSql('UPDATE project SET contractor_id = (SELECT id FROM contractor WHERE short_name = \'Creative\') WHERE contractor_id IS NULL');
  19.         $this->addSql('ALTER TABLE project DROP CONSTRAINT FK_2FB3D0EEB0265DC7');
  20.         $this->addSql('ALTER TABLE project ALTER contractor_id SET NOT NULL');
  21.         $this->addSql('ALTER TABLE project ADD CONSTRAINT FK_2FB3D0EEB0265DC7 FOREIGN KEY (contractor_id) REFERENCES contractor (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
  22.     }
  23.     public function down(Schema $schema): void
  24.     {
  25.         $this->addSql('ALTER TABLE project DROP CONSTRAINT fk_2fb3d0eeb0265dc7');
  26.         $this->addSql('ALTER TABLE project ALTER contractor_id DROP NOT NULL');
  27.         $this->addSql('ALTER TABLE project ADD CONSTRAINT fk_2fb3d0eeb0265dc7 FOREIGN KEY (contractor_id) REFERENCES contractor (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
  28.     }
  29. }