migrations/Version20230511062917.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 Version20230511062917 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('
  19.         INSERT INTO company (id, uuid, legal_name, person_name, email, phone, banking_details, manager_id, address_id, website, vat_type, date_created)
  20.         SELECT
  21.             m.id,
  22.             UUID(),
  23.             m.name,
  24.             IFNULL(m.contact_person, m.name),
  25.             IFNULL(m.contact_email, \'Unknown\'),
  26.             m.contact_phone,
  27.             m.banking_details,
  28.             m.manager_id,
  29.             m.address_id,
  30.             m.website,
  31.             \'tax.type.vat_std\',
  32.             NOW()
  33.         FROM manufacturer m
  34.     ');
  35.         // This part of the migration is to update the company_id in the manufacturer entities
  36.         $this->addSql('
  37.             UPDATE manufacturer m
  38.             SET m.company_id = (
  39.                 SELECT c.id 
  40.                 FROM company c 
  41.                 WHERE c.id = m.id
  42.             )
  43.         ');
  44.         // update the foreign key for the users associated with the manufacturer
  45.         $this->addSql('
  46.         UPDATE user u
  47.         SET u.company_id = (
  48.             SELECT c.id 
  49.             FROM company c 
  50.             WHERE c.id = u.manufacturer_id
  51.         )
  52.     ');
  53.     }
  54.     public function down(Schema $schema): void
  55.     {}
  56. }