<?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 Version20230511062917 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 (id, uuid, legal_name, person_name, email, phone, banking_details, manager_id, address_id, website, vat_type, date_created)
SELECT
m.id,
UUID(),
m.name,
IFNULL(m.contact_person, m.name),
IFNULL(m.contact_email, \'Unknown\'),
m.contact_phone,
m.banking_details,
m.manager_id,
m.address_id,
m.website,
\'tax.type.vat_std\',
NOW()
FROM manufacturer m
');
// This part of the migration is to update the company_id in the manufacturer entities
$this->addSql('
UPDATE manufacturer m
SET m.company_id = (
SELECT c.id
FROM company c
WHERE c.id = m.id
)
');
// update the foreign key for the users associated with the manufacturer
$this->addSql('
UPDATE user u
SET u.company_id = (
SELECT c.id
FROM company c
WHERE c.id = u.manufacturer_id
)
');
}
public function down(Schema $schema): void
{}
}