Commit 646d11e6 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Migration: add updated_by/created_by to all 17 tables with autoTrackAuthor

Tables fixed (already applied to live DB directly):
reservations, academy_settlements, achievement_definitions,
activity_subscriptions, facility_grids, facility_monthly_plans,
facility_zone_schedules, player_evaluations, player_injuries,
pool_bookings, pool_configurations, pool_schedules,
sa_player_documents, sa_pricing_rules, tournaments,
training_groups, training_sessions

Migration is idempotent — checks column existence before ALTER.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 299e67a6
<?php <?php
declare(strict_types=1); declare(strict_types=1);
return [ return function (\App\Core\Database $db) {
'up' => "ALTER TABLE `reservations` ADD COLUMN `updated_by` BIGINT UNSIGNED NULL AFTER `created_by`", $tables = [
'down' => "ALTER TABLE `reservations` DROP COLUMN `updated_by`", 'reservations',
]; 'academy_settlements',
'achievement_definitions',
'activity_subscriptions',
'facility_grids',
'facility_monthly_plans',
'facility_zone_schedules',
'player_evaluations',
'player_injuries',
'pool_bookings',
'pool_configurations',
'pool_schedules',
'sa_player_documents',
'sa_pricing_rules',
'tournaments',
'training_groups',
'training_sessions',
];
foreach ($tables as $table) {
$exists = $db->selectOne(
"SELECT 1 FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = ? AND column_name = 'updated_by'",
[$table]
);
if (!$exists) {
$db->raw("ALTER TABLE `{$table}` ADD COLUMN `updated_by` BIGINT UNSIGNED NULL");
}
}
// Also ensure created_by exists on tables that use autoTrackAuthor
$needsCreatedBy = ['achievement_definitions', 'player_injuries'];
foreach ($needsCreatedBy as $table) {
$exists = $db->selectOne(
"SELECT 1 FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = ? AND column_name = 'created_by'",
[$table]
);
if (!$exists) {
$db->raw("ALTER TABLE `{$table}` ADD COLUMN `created_by` BIGINT UNSIGNED NULL");
}
}
};
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