migrations/Version20250728110000.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\DBAL\Types\Types;
  6. use Doctrine\Migrations\AbstractMigration;
  7. final class Version20250728110000 extends AbstractMigration
  8. {
  9.     public function getDescription(): string
  10.     {
  11.         return 'Add process_type column to dossier_type table and populate with mapped data from category';
  12.     }
  13.     public function up(Schema $schema): void
  14.     {
  15.         $this->skipIf(
  16.             $schema->getTable('dossier_type')->hasColumn('process_type'),
  17.             'The process_type column already exists in the dossier_type table'
  18.         );
  19.         // Add the new process_type column as nullable first
  20.         $table $schema->getTable('dossier_type');
  21.         $table->addColumn('process_type'Types::STRING)
  22.             ->setLength(40)
  23.             ->setNotnull(false)
  24.             ->setDefault(null);
  25.     }
  26.     public function postUp(Schema $schema): void
  27.     {
  28.         // Migrate data from category to process_type
  29.         $this->connection->executeStatement("
  30.             UPDATE dossier_type 
  31.             SET process_type = CASE 
  32.                 WHEN category IN ('reimbursement_national', 'reimbursement_foreign', 'reimbursement_thirdparty') THEN 'reimbursement_process'
  33.                 WHEN category = 'student_status_change' THEN 'member_school_certificate_process'
  34.                 WHEN category IN ('new_member', 'new_member_B2B') THEN 'member_application_process'
  35.                 ELSE 'default_process'
  36.             END
  37.         ");
  38.         // Note: The category column is kept for backward compatibility during migration to V2
  39.         // It should be removed in a future migration after V2 is complete
  40.         // A second migration will make process_type NOT NULL after data is populated
  41.     }
  42.     public function down(Schema $schema): void
  43.     {
  44.         $this->skipIf(
  45.             !$schema->getTable('dossier_type')->hasColumn('process_type'),
  46.             'The process_type column does not exist in the dossier_type table'
  47.         );
  48.         // Drop the process_type column
  49.         $table $schema->getTable('dossier_type');
  50.         $table->dropColumn('process_type');
  51.     }
  52. }