<?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 Version20260622084240 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('ALTER TABLE channel_company_contacts DROP FOREIGN KEY FK_126D19A5E7A1254A');
$this->addSql('DROP INDEX IDX_126D19A5E7A1254A ON channel_company_contacts');
$this->addSql('ALTER TABLE channel_company_contacts CHANGE contact_id channel_contact_id VARCHAR(36) NOT NULL');
$this->addSql('
UPDATE channel_company_contacts company_contacts
INNER JOIN channel_company company ON company.id = company_contacts.company_id
INNER JOIN channel_contacts contacts
ON contacts.contact_id = company_contacts.channel_contact_id
AND contacts.channel_id = company.channel_id
SET company_contacts.channel_contact_id = contacts.id
');
// Log unknown channel_contact_id
$this->addSql('
CREATE TABLE IF NOT EXISTS _migration_backup_channel_company_contacts_20260622 AS
SELECT company_contacts.* FROM channel_company_contacts company_contacts
LEFT JOIN channel_contacts contacts ON contacts.id = company_contacts.channel_contact_id
WHERE contacts.id IS NULL
');
// Purge orphan lines: channel_contact_id is unknown
$this->addSql('
DELETE company_contacts FROM channel_company_contacts company_contacts
LEFT JOIN channel_contacts contacts ON contacts.id = company_contacts.channel_contact_id
WHERE contacts.id IS NULL
');
$this->addSql('ALTER TABLE channel_company_contacts ADD CONSTRAINT FK_126D19A5516875DC FOREIGN KEY (channel_contact_id) REFERENCES channel_contacts (id) ON DELETE CASCADE');
$this->addSql('CREATE INDEX IDX_126D19A5516875DC ON channel_company_contacts (channel_contact_id)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE channel_company_contacts DROP FOREIGN KEY FK_126D19A5516875DC');
$this->addSql('DROP INDEX IDX_126D19A5516875DC ON channel_company_contacts');
$this->addSql('ALTER TABLE channel_company_contacts CHANGE channel_contact_id contact_id VARCHAR(36) NOT NULL');
$this->addSql('ALTER TABLE channel_company_contacts ADD CONSTRAINT FK_126D19A5E7A1254A FOREIGN KEY (contact_id) REFERENCES contacts (id) ON DELETE CASCADE');
$this->addSql('CREATE INDEX IDX_126D19A5E7A1254A ON channel_company_contacts (contact_id)');
}
}