<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20241120134000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Set effective date for existing non closed member applications';
}
public function up(Schema $schema): void
{
// This migration sets the effective date for member applications
// The effective date is calculated as: first day of next month based on membership start date or created date
$this->addSql("
UPDATE member_application
SET
-- Calculate effective date as first day of next month
-- COALESCE: takes membership start date if available, otherwise uses created date
-- DATE_FORMAT with '%Y-%m-01': formats date to first day of the month
-- DATE_ADD with INTERVAL 1 MONTH: adds one month to get first day of next month
effective_date = DATE_ADD(
DATE_FORMAT(
COALESCE(member_ship_start_at, created_at),
'%Y-%m-01'
),
INTERVAL 1 MONTH
)
-- Only update records with these specific processing statuses
WHERE processing_status IN ('processing', 'pending', 'incomplete')
-- Only update if effective_date hasn't been set already
AND effective_date IS NULL
");
}
public function down(Schema $schema): void
{
// Reset effective date to NULL for the affected records
$this->addSql("
UPDATE member_application
SET effective_date = NULL
WHERE processing_status IN ('processing', 'pending', 'incomplete')
");
}
}