Commit 46f03bbf authored by Fares's avatar Fares

fix(migration): make Phase_100_002 idempotent to handle pre-existing columns

The medical_grace_deadline column already exists in the live DB from a
prior partial run. Converted to a closure-based migration that checks
information_schema before altering.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 641ec646
<?php <?php
declare(strict_types=1); declare(strict_types=1);
return [ return function (\App\Core\Database $db): void {
'up' => " $exists = $db->selectOne(
ALTER TABLE sa_group_players ADD COLUMN medical_grace_deadline DATE NULL DEFAULT NULL COMMENT 'Deadline for submitting medical cert' AFTER status; "SELECT 1 FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'sa_group_players' AND column_name = 'medical_grace_deadline'"
INSERT INTO system_config (config_key, config_value, config_group, label_ar, field_type, created_at, updated_at) );
VALUES ('sa.medical_grace_days', '14', 'sports_activity', 'مهلة تقديم الشهادة الطبية (بالأيام)', 'number', NOW(), NOW()) if (!$exists) {
ON DUPLICATE KEY UPDATE config_key = config_key; $db->raw("ALTER TABLE sa_group_players ADD COLUMN medical_grace_deadline DATE NULL DEFAULT NULL COMMENT 'Deadline for submitting medical cert' AFTER status");
", }
'down' => "
ALTER TABLE sa_group_players DROP COLUMN medical_grace_deadline; $configExists = $db->selectOne("SELECT 1 FROM system_config WHERE config_key = 'sa.medical_grace_days'");
DELETE FROM system_config WHERE config_key = 'sa.medical_grace_days'; if (!$configExists) {
", $db->raw("INSERT INTO system_config (config_key, config_value, config_group, label_ar, field_type, created_at, updated_at) VALUES ('sa.medical_grace_days', '14', 'sports_activity', 'مهلة تقديم الشهادة الطبية (بالأيام)', 'number', NOW(), NOW())");
]; }
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment