<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Migration: Refactor Privatisation to use Contact relationship
*
* IMPORTANT: This migration only handles schema changes.
* After running this migration, you MUST run the data migration command:
* php bin/console app:migrate-privatisation-to-contact
*/
final class Version20250707125645 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add Contact relationship to Privatisation and prepare for data migration';
}
public function up(Schema $schema): void
{
// Step 1: Add new columns to Contact table
$this->addSql('ALTER TABLE contact ADD company VARCHAR(255) DEFAULT NULL');
// Step 2: Add new columns to Privatisation table (keep old ones for data migration)
$this->addSql('ALTER TABLE privatisation ADD contact_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE privatisation ADD offer VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE privatisation ADD client_commentary LONGTEXT DEFAULT NULL');
$this->addSql('ALTER TABLE privatisation ADD comment LONGTEXT DEFAULT NULL');
// Step 3: Create foreign key constraint (nullable for now)
$this->addSql('ALTER TABLE privatisation ADD CONSTRAINT FK_12C3A675E7A1254A FOREIGN KEY (contact_id) REFERENCES contact (id)');
$this->addSql('CREATE INDEX IDX_12C3A675E7A1254A ON privatisation (contact_id)');
// Note: Old columns will be dropped in a separate migration after data migration
}
public function down(Schema $schema): void
{
// Remove the additions made in up()
$this->addSql('ALTER TABLE contact DROP company');
$this->addSql('ALTER TABLE privatisation DROP FOREIGN KEY FK_12C3A675E7A1254A');
$this->addSql('DROP INDEX IDX_12C3A675E7A1254A ON privatisation');
$this->addSql('ALTER TABLE privatisation DROP contact_id');
$this->addSql('ALTER TABLE privatisation DROP offer');
$this->addSql('ALTER TABLE privatisation DROP client_commentary');
$this->addSql('ALTER TABLE privatisation DROP comment');
}
}