migrations/Version20250707125645.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: Refactor Privatisation to use Contact relationship
  8.  * 
  9.  * IMPORTANT: This migration only handles schema changes.
  10.  * After running this migration, you MUST run the data migration command:
  11.  * php bin/console app:migrate-privatisation-to-contact
  12.  */
  13. final class Version20250707125645 extends AbstractMigration
  14. {
  15.     public function getDescription(): string
  16.     {
  17.         return 'Add Contact relationship to Privatisation and prepare for data migration';
  18.     }
  19.     public function up(Schema $schema): void
  20.     {
  21.         // Step 1: Add new columns to Contact table
  22.         $this->addSql('ALTER TABLE contact ADD company VARCHAR(255) DEFAULT NULL');
  23.         
  24.         // Step 2: Add new columns to Privatisation table (keep old ones for data migration)
  25.         $this->addSql('ALTER TABLE privatisation ADD contact_id INT DEFAULT NULL');
  26.         $this->addSql('ALTER TABLE privatisation ADD offer VARCHAR(255) DEFAULT NULL');
  27.         $this->addSql('ALTER TABLE privatisation ADD client_commentary LONGTEXT DEFAULT NULL');
  28.         $this->addSql('ALTER TABLE privatisation ADD comment LONGTEXT DEFAULT NULL');
  29.         
  30.         // Step 3: Create foreign key constraint (nullable for now)
  31.         $this->addSql('ALTER TABLE privatisation ADD CONSTRAINT FK_12C3A675E7A1254A FOREIGN KEY (contact_id) REFERENCES contact (id)');
  32.         $this->addSql('CREATE INDEX IDX_12C3A675E7A1254A ON privatisation (contact_id)');
  33.         
  34.         // Note: Old columns will be dropped in a separate migration after data migration
  35.     }
  36.     public function down(Schema $schema): void
  37.     {
  38.         // Remove the additions made in up()
  39.         $this->addSql('ALTER TABLE contact DROP company');
  40.         $this->addSql('ALTER TABLE privatisation DROP FOREIGN KEY FK_12C3A675E7A1254A');
  41.         $this->addSql('DROP INDEX IDX_12C3A675E7A1254A ON privatisation');
  42.         $this->addSql('ALTER TABLE privatisation DROP contact_id');
  43.         $this->addSql('ALTER TABLE privatisation DROP offer');
  44.         $this->addSql('ALTER TABLE privatisation DROP client_commentary');
  45.         $this->addSql('ALTER TABLE privatisation DROP comment');
  46.     }
  47. }