<?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 Version20230321160908 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->addSql('ALTER TABLE product ADD supplier_id VARCHAR(255) DEFAULT NULL');
$this->addSql('INSERT INTO supplier (id, name, created_at, updated_at) SELECT uuid(), supplier, now(), now() FROM product WHERE supplier <> "" GROUP BY supplier');
$this->addSql('UPDATE product SET supplier_id = (SELECT id FROM supplier WHERE supplier.name = product.supplier) WHERE supplier <> ""');
$this->addSql('ALTER TABLE product DROP supplier');
$this->addSql('ALTER TABLE product ADD CONSTRAINT FK_D34A04AD2ADD6D8C FOREIGN KEY (supplier_id) REFERENCES supplier (id)');
$this->addSql('CREATE INDEX IDX_D34A04AD2ADD6D8C ON product (supplier_id)');
$this->addSql('UPDATE product SET sold_to_id=null where sold_to_id = (select id from client where name = "")');
$this->addSql('DELETE FROM client where name = ""');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE product DROP FOREIGN KEY FK_D34A04AD2ADD6D8C');
$this->addSql('DROP INDEX IDX_D34A04AD2ADD6D8C ON product');
$this->addSql('ALTER TABLE product ADD supplier VARCHAR(255) NOT NULL, DROP supplier_id');
}
}