migrations/Version20230511071329.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 Version20230511071329 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 (uuid, legal_name, person_name, email, phone, banking_details, address_id, vat_type, vat_nr, registration_number, date_created)
  20.         SELECT
  21.             s.uuid,
  22.             s.name,
  23.             IFNULL(s.person_name, s.name),
  24.             IFNULL(s.email, \'Unknown\'),
  25.             s.phone,
  26.             s.banking_details,
  27.             s.address_id,
  28.             IFNULL(s.vat_type, \'tax.type.vat_std\'),
  29.             s.vatnr,
  30.             s.registration_nr,
  31.             NOW()
  32.         FROM supplier s
  33.     ');
  34.         // This part of the migration is to update the company_id in the customer entities
  35.         $this->addSql('
  36.         UPDATE supplier s
  37.         JOIN company co ON co.uuid = s.uuid
  38.         SET s.company_id = co.id
  39.     ');
  40.         // update the foreign key for the users associated with the customer
  41.         $this->addSql('
  42.         UPDATE invoice i
  43.         JOIN supplier s ON i.supplier_id = s.id
  44.         JOIN company co ON co.id = s.company_id
  45.         SET i.company_id = co.id
  46.     ');
  47.     }
  48.     public function down(Schema $schema): void
  49.     {}
  50. }