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