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