migrations/Version20230321160908.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 Version20230321160908 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  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('ALTER TABLE product ADD supplier_id VARCHAR(255) DEFAULT NULL');
  19.         $this->addSql('INSERT INTO supplier (id, name, created_at, updated_at) SELECT uuid(), supplier, now(), now() FROM product WHERE supplier <> "" GROUP BY supplier');
  20.         $this->addSql('UPDATE product SET supplier_id = (SELECT id FROM supplier WHERE supplier.name = product.supplier) WHERE supplier <> ""');
  21.         $this->addSql('ALTER TABLE product DROP supplier');
  22.         $this->addSql('ALTER TABLE product ADD CONSTRAINT FK_D34A04AD2ADD6D8C FOREIGN KEY (supplier_id) REFERENCES supplier (id)');
  23.         $this->addSql('CREATE INDEX IDX_D34A04AD2ADD6D8C ON product (supplier_id)');
  24.         $this->addSql('UPDATE product SET sold_to_id=null where sold_to_id = (select id from client where name = "")');
  25.         $this->addSql('DELETE FROM client where name = ""');
  26.     }
  27.     public function down(Schema $schema): void
  28.     {
  29.         // this down() migration is auto-generated, please modify it to your needs
  30.         $this->addSql('ALTER TABLE product DROP FOREIGN KEY FK_D34A04AD2ADD6D8C');
  31.         $this->addSql('DROP INDEX IDX_D34A04AD2ADD6D8C ON product');
  32.         $this->addSql('ALTER TABLE product ADD supplier VARCHAR(255) NOT NULL, DROP supplier_id');
  33.     }
  34. }