<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20250728110000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add process_type column to dossier_type table and populate with mapped data from category';
}
public function up(Schema $schema): void
{
$this->skipIf(
$schema->getTable('dossier_type')->hasColumn('process_type'),
'The process_type column already exists in the dossier_type table'
);
// Add the new process_type column as nullable first
$table = $schema->getTable('dossier_type');
$table->addColumn('process_type', Types::STRING)
->setLength(40)
->setNotnull(false)
->setDefault(null);
}
public function postUp(Schema $schema): void
{
// Migrate data from category to process_type
$this->connection->executeStatement("
UPDATE dossier_type
SET process_type = CASE
WHEN category IN ('reimbursement_national', 'reimbursement_foreign', 'reimbursement_thirdparty') THEN 'reimbursement_process'
WHEN category = 'student_status_change' THEN 'member_school_certificate_process'
WHEN category IN ('new_member', 'new_member_B2B') THEN 'member_application_process'
ELSE 'default_process'
END
");
// Note: The category column is kept for backward compatibility during migration to V2
// It should be removed in a future migration after V2 is complete
// A second migration will make process_type NOT NULL after data is populated
}
public function down(Schema $schema): void
{
$this->skipIf(
!$schema->getTable('dossier_type')->hasColumn('process_type'),
'The process_type column does not exist in the dossier_type table'
);
// Drop the process_type column
$table = $schema->getTable('dossier_type');
$table->dropColumn('process_type');
}
}