<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Migration: Clean up old Privatisation columns after data migration
*
* IMPORTANT: Only run this migration AFTER:
* 1. Running the schema migration (Version20250707125645)
* 2. Running the data migration command: php bin/console app:migrate-privatisation-to-contact
* 3. Verifying that all data has been migrated correctly
*/
final class Version20250707125647 extends AbstractMigration
{
public function getDescription(): string
{
return 'Remove old contact columns from Privatisation table and make contact_id required';
}
public function up(Schema $schema): void
{
// Make contact_id required (it should be populated by now)
$this->addSql('ALTER TABLE privatisation MODIFY contact_id INT NOT NULL');
// Make offer required (it should be populated by now)
$this->addSql('ALTER TABLE privatisation MODIFY offer VARCHAR(255) NOT NULL');
// Drop old contact-related columns
$this->addSql('ALTER TABLE privatisation DROP company');
$this->addSql('ALTER TABLE privatisation DROP firstname');
$this->addSql('ALTER TABLE privatisation DROP lastname');
$this->addSql('ALTER TABLE privatisation DROP email');
$this->addSql('ALTER TABLE privatisation DROP phone_number');
$this->addSql('ALTER TABLE privatisation DROP postal_code');
$this->addSql('ALTER TABLE privatisation DROP city');
$this->addSql('ALTER TABLE privatisation DROP address');
$this->addSql('ALTER TABLE privatisation DROP country');
$this->addSql('ALTER TABLE privatisation DROP checked_accept_promotion');
// Drop old renamed columns
$this->addSql('ALTER TABLE privatisation DROP duration');
$this->addSql('ALTER TABLE privatisation DROP commentary');
}
public function down(Schema $schema): void
{
// Restore old columns (this is mainly for schema rollback, data won't be restored)
$this->addSql('ALTER TABLE privatisation ADD company VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE privatisation ADD firstname VARCHAR(255) NOT NULL');
$this->addSql('ALTER TABLE privatisation ADD lastname VARCHAR(255) NOT NULL');
$this->addSql('ALTER TABLE privatisation ADD email VARCHAR(255) NOT NULL');
$this->addSql('ALTER TABLE privatisation ADD phone_number VARCHAR(255) NOT NULL');
$this->addSql('ALTER TABLE privatisation ADD postal_code VARCHAR(255) NOT NULL');
$this->addSql('ALTER TABLE privatisation ADD city VARCHAR(255) NOT NULL');
$this->addSql('ALTER TABLE privatisation ADD address VARCHAR(255) NOT NULL');
$this->addSql('ALTER TABLE privatisation ADD country VARCHAR(255) NOT NULL');
$this->addSql('ALTER TABLE privatisation ADD checked_accept_promotion TINYINT(1) NOT NULL');
$this->addSql('ALTER TABLE privatisation ADD duration INT NOT NULL');
$this->addSql('ALTER TABLE privatisation ADD commentary LONGTEXT DEFAULT NULL');
// Make contact_id and offer nullable again
$this->addSql('ALTER TABLE privatisation MODIFY contact_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE privatisation MODIFY offer VARCHAR(255) DEFAULT NULL');
}
}