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
declare(strict_types=1);
return [
'up' => "
ALTER TABLE sa_group_players ADD COLUMN medical_grace_deadline DATE NULL DEFAULT NULL COMMENT 'Deadline for submitting medical cert' AFTER status;
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())
ON DUPLICATE KEY UPDATE config_key = config_key;
",
'down' => "
ALTER TABLE sa_group_players DROP COLUMN medical_grace_deadline;
DELETE FROM system_config WHERE config_key = 'sa.medical_grace_days';
",
];
return function (\App\Core\Database $db): void {
$exists = $db->selectOne(
"SELECT 1 FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'sa_group_players' AND column_name = 'medical_grace_deadline'"
);
if (!$exists) {
$db->raw("ALTER TABLE sa_group_players ADD COLUMN medical_grace_deadline DATE NULL DEFAULT NULL COMMENT 'Deadline for submitting medical cert' AFTER status");
}
$configExists = $db->selectOne("SELECT 1 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