migrations/Version20250707125647.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.  * Migration: Clean up old Privatisation columns after data migration
  8.  * 
  9.  * IMPORTANT: Only run this migration AFTER:
  10.  * 1. Running the schema migration (Version20250707125645)
  11.  * 2. Running the data migration command: php bin/console app:migrate-privatisation-to-contact
  12.  * 3. Verifying that all data has been migrated correctly
  13.  */
  14. final class Version20250707125647 extends AbstractMigration
  15. {
  16.     public function getDescription(): string
  17.     {
  18.         return 'Remove old contact columns from Privatisation table and make contact_id required';
  19.     }
  20.     public function up(Schema $schema): void
  21.     {
  22.         // Make contact_id required (it should be populated by now)
  23.         $this->addSql('ALTER TABLE privatisation MODIFY contact_id INT NOT NULL');
  24.         
  25.         // Make offer required (it should be populated by now)
  26.         $this->addSql('ALTER TABLE privatisation MODIFY offer VARCHAR(255) NOT NULL');
  27.         
  28.         // Drop old contact-related columns
  29.         $this->addSql('ALTER TABLE privatisation DROP company');
  30.         $this->addSql('ALTER TABLE privatisation DROP firstname');
  31.         $this->addSql('ALTER TABLE privatisation DROP lastname');
  32.         $this->addSql('ALTER TABLE privatisation DROP email');
  33.         $this->addSql('ALTER TABLE privatisation DROP phone_number');
  34.         $this->addSql('ALTER TABLE privatisation DROP postal_code');
  35.         $this->addSql('ALTER TABLE privatisation DROP city');
  36.         $this->addSql('ALTER TABLE privatisation DROP address');
  37.         $this->addSql('ALTER TABLE privatisation DROP country');
  38.         $this->addSql('ALTER TABLE privatisation DROP checked_accept_promotion');
  39.         
  40.         // Drop old renamed columns
  41.         $this->addSql('ALTER TABLE privatisation DROP duration');
  42.         $this->addSql('ALTER TABLE privatisation DROP commentary');
  43.     }
  44.     public function down(Schema $schema): void
  45.     {
  46.         // Restore old columns (this is mainly for schema rollback, data won't be restored)
  47.         $this->addSql('ALTER TABLE privatisation ADD company VARCHAR(255) DEFAULT NULL');
  48.         $this->addSql('ALTER TABLE privatisation ADD firstname VARCHAR(255) NOT NULL');
  49.         $this->addSql('ALTER TABLE privatisation ADD lastname VARCHAR(255) NOT NULL');
  50.         $this->addSql('ALTER TABLE privatisation ADD email VARCHAR(255) NOT NULL');
  51.         $this->addSql('ALTER TABLE privatisation ADD phone_number VARCHAR(255) NOT NULL');
  52.         $this->addSql('ALTER TABLE privatisation ADD postal_code VARCHAR(255) NOT NULL');
  53.         $this->addSql('ALTER TABLE privatisation ADD city VARCHAR(255) NOT NULL');
  54.         $this->addSql('ALTER TABLE privatisation ADD address VARCHAR(255) NOT NULL');
  55.         $this->addSql('ALTER TABLE privatisation ADD country VARCHAR(255) NOT NULL');
  56.         $this->addSql('ALTER TABLE privatisation ADD checked_accept_promotion TINYINT(1) NOT NULL');
  57.         $this->addSql('ALTER TABLE privatisation ADD duration INT NOT NULL');
  58.         $this->addSql('ALTER TABLE privatisation ADD commentary LONGTEXT DEFAULT NULL');
  59.         
  60.         // Make contact_id and offer nullable again
  61.         $this->addSql('ALTER TABLE privatisation MODIFY contact_id INT DEFAULT NULL');
  62.         $this->addSql('ALTER TABLE privatisation MODIFY offer VARCHAR(255) DEFAULT NULL');
  63.     }