migrations/Version20260622084240.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 Version20260622084240 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('ALTER TABLE channel_company_contacts DROP FOREIGN KEY FK_126D19A5E7A1254A');
  19. $this->addSql('DROP INDEX IDX_126D19A5E7A1254A ON channel_company_contacts');
  20. $this->addSql('ALTER TABLE channel_company_contacts CHANGE contact_id channel_contact_id VARCHAR(36) NOT NULL');
  21. $this->addSql('
  22. UPDATE channel_company_contacts company_contacts
  23. INNER JOIN channel_company company ON company.id = company_contacts.company_id
  24. INNER JOIN channel_contacts contacts
  25. ON contacts.contact_id = company_contacts.channel_contact_id
  26. AND contacts.channel_id = company.channel_id
  27. SET company_contacts.channel_contact_id = contacts.id
  28. ');
  29. // Log unknown channel_contact_id
  30. $this->addSql('
  31. CREATE TABLE IF NOT EXISTS _migration_backup_channel_company_contacts_20260622 AS
  32. SELECT company_contacts.* FROM channel_company_contacts company_contacts
  33. LEFT JOIN channel_contacts contacts ON contacts.id = company_contacts.channel_contact_id
  34. WHERE contacts.id IS NULL
  35. ');
  36. // Purge orphan lines: channel_contact_id is unknown
  37. $this->addSql('
  38. DELETE company_contacts FROM channel_company_contacts company_contacts
  39. LEFT JOIN channel_contacts contacts ON contacts.id = company_contacts.channel_contact_id
  40. WHERE contacts.id IS NULL
  41. ');
  42. $this->addSql('ALTER TABLE channel_company_contacts ADD CONSTRAINT FK_126D19A5516875DC FOREIGN KEY (channel_contact_id) REFERENCES channel_contacts (id) ON DELETE CASCADE');
  43. $this->addSql('CREATE INDEX IDX_126D19A5516875DC ON channel_company_contacts (channel_contact_id)');
  44. }
  45. public function down(Schema $schema): void
  46. {
  47. // this down() migration is auto-generated, please modify it to your needs
  48. $this->addSql('ALTER TABLE channel_company_contacts DROP FOREIGN KEY FK_126D19A5516875DC');
  49. $this->addSql('DROP INDEX IDX_126D19A5516875DC ON channel_company_contacts');
  50. $this->addSql('ALTER TABLE channel_company_contacts CHANGE channel_contact_id contact_id VARCHAR(36) NOT NULL');
  51. $this->addSql('ALTER TABLE channel_company_contacts ADD CONSTRAINT FK_126D19A5E7A1254A FOREIGN KEY (contact_id) REFERENCES contacts (id) ON DELETE CASCADE');
  52. $this->addSql('CREATE INDEX IDX_126D19A5E7A1254A ON channel_company_contacts (contact_id)');
  53. }
  54. }