<?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 Version20230511071329 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('
INSERT INTO company (uuid, legal_name, person_name, email, phone, banking_details, address_id, vat_type, vat_nr, registration_number, date_created)
SELECT
s.uuid,
s.name,
IFNULL(s.person_name, s.name),
IFNULL(s.email, \'Unknown\'),
s.phone,
s.banking_details,
s.address_id,
IFNULL(s.vat_type, \'tax.type.vat_std\'),
s.vatnr,
s.registration_nr,
NOW()
FROM supplier s
');
// This part of the migration is to update the company_id in the customer entities
$this->addSql('
UPDATE supplier s
JOIN company co ON co.uuid = s.uuid
SET s.company_id = co.id
');
// update the foreign key for the users associated with the customer
$this->addSql('
UPDATE invoice i
JOIN supplier s ON i.supplier_id = s.id
JOIN company co ON co.id = s.company_id
SET i.company_id = co.id
');
}
public function down(Schema $schema): void
{}
}