Commit cd8ded02 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix 3 deploy failures: idempotent migration, reserved word, and seed column mismatch

- Phase_64_002: Convert to closure-based migration with column existence checks
  (was failing because movement_type already existed from partial prior run)
- Phase_65_012: Backtick-quote `row_number` (MySQL 8.0 reserved word)
- Phase_64_001 seed: Use description_ar instead of non-existent description column,
  remove is_active (not in schema), add config_type and group_name
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent c1f6b45a
<?php <?php
declare(strict_types=1); declare(strict_types=1);
return [ return function (\App\Core\Database $db): void {
'up' => " $table = 'daily_cash_movements';
ALTER TABLE `daily_cash_movements` ADD COLUMN `movement_type` VARCHAR(50) NULL AFTER `movement_date`;
ALTER TABLE `daily_cash_movements` ADD COLUMN `direction` ENUM('in','out') NULL AFTER `movement_type`; $columns = [
ALTER TABLE `daily_cash_movements` ADD COLUMN `amount` DECIMAL(15,2) NOT NULL DEFAULT 0.00 AFTER `direction`; ['movement_type', "VARCHAR(50) NULL AFTER `movement_date`"],
ALTER TABLE `daily_cash_movements` ADD COLUMN `description` VARCHAR(500) NULL AFTER `amount`; ['direction', "ENUM('in','out') NULL AFTER `movement_type`"],
ALTER TABLE `daily_cash_movements` ADD COLUMN `reference_type` VARCHAR(100) NULL AFTER `description`; ['amount', "DECIMAL(15,2) NOT NULL DEFAULT 0.00 AFTER `direction`"],
ALTER TABLE `daily_cash_movements` ADD COLUMN `reference_id` INT UNSIGNED NULL AFTER `reference_type`; ['description', "VARCHAR(500) NULL AFTER `amount`"],
ALTER TABLE `daily_cash_movements` DROP INDEX IF EXISTS `uk_date_bank`; ['reference_type', "VARCHAR(100) NULL AFTER `description`"],
ALTER TABLE `daily_cash_movements` DROP INDEX IF EXISTS `uk_date_safe`; ['reference_id', "INT UNSIGNED NULL AFTER `reference_type`"],
ALTER TABLE `daily_cash_movements` ADD INDEX `idx_movement_date` (`movement_date`); ];
ALTER TABLE `daily_cash_movements` ADD INDEX `idx_movement_type` (`movement_type`);
ALTER TABLE `daily_cash_movements` ADD INDEX `idx_direction` (`direction`)", foreach ($columns as [$col, $def]) {
$exists = $db->selectOne(
"SELECT 1 FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = ? AND column_name = ?",
[$table, $col]
);
if (!$exists) {
$db->raw("ALTER TABLE `{$table}` ADD COLUMN `{$col}` {$def}");
}
}
$db->raw("ALTER TABLE `{$table}` DROP INDEX IF EXISTS `uk_date_bank`");
$db->raw("ALTER TABLE `{$table}` DROP INDEX IF EXISTS `uk_date_safe`");
$idx = $db->selectOne("SELECT 1 FROM information_schema.statistics WHERE table_schema = DATABASE() AND table_name = ? AND index_name = 'idx_movement_date'", [$table]);
if (!$idx) {
$db->raw("ALTER TABLE `{$table}` ADD INDEX `idx_movement_date` (`movement_date`)");
}
$idx = $db->selectOne("SELECT 1 FROM information_schema.statistics WHERE table_schema = DATABASE() AND table_name = ? AND index_name = 'idx_movement_type'", [$table]);
if (!$idx) {
$db->raw("ALTER TABLE `{$table}` ADD INDEX `idx_movement_type` (`movement_type`)");
}
$idx = $db->selectOne("SELECT 1 FROM information_schema.statistics WHERE table_schema = DATABASE() AND table_name = ? AND index_name = 'idx_direction'", [$table]);
if (!$idx) {
$db->raw("ALTER TABLE `{$table}` ADD INDEX `idx_direction` (`direction`)");
}
};
'down' => "
ALTER TABLE `daily_cash_movements` DROP INDEX IF EXISTS `idx_direction`;
ALTER TABLE `daily_cash_movements` DROP INDEX IF EXISTS `idx_movement_type`;
ALTER TABLE `daily_cash_movements` DROP INDEX IF EXISTS `idx_movement_date`;
ALTER TABLE `daily_cash_movements` DROP COLUMN IF EXISTS `reference_id`;
ALTER TABLE `daily_cash_movements` DROP COLUMN IF EXISTS `reference_type`;
ALTER TABLE `daily_cash_movements` DROP COLUMN IF EXISTS `description`;
ALTER TABLE `daily_cash_movements` DROP COLUMN IF EXISTS `amount`;
ALTER TABLE `daily_cash_movements` DROP COLUMN IF EXISTS `direction`;
ALTER TABLE `daily_cash_movements` DROP COLUMN IF EXISTS `movement_type`;
ALTER TABLE `daily_cash_movements` ADD UNIQUE KEY `uk_date_bank` (`movement_date`, `bank_account_id`);
ALTER TABLE `daily_cash_movements` ADD UNIQUE KEY `uk_date_safe` (`movement_date`, `safe_id`)",
];
...@@ -8,7 +8,7 @@ CREATE TABLE IF NOT EXISTS playground_schedule_slots ( ...@@ -8,7 +8,7 @@ CREATE TABLE IF NOT EXISTS playground_schedule_slots (
schedule_id INT UNSIGNED NOT NULL, schedule_id INT UNSIGNED NOT NULL,
slot_date DATE NOT NULL, slot_date DATE NOT NULL,
slot_hour TIME NOT NULL, slot_hour TIME NOT NULL,
row_number INT UNSIGNED NULL, `row_number` INT UNSIGNED NULL,
coach_id INT UNSIGNED NULL, coach_id INT UNSIGNED NULL,
academy_id INT UNSIGNED NULL, academy_id INT UNSIGNED NULL,
group_type VARCHAR(30) NULL, group_type VARCHAR(30) NULL,
......
...@@ -16,12 +16,14 @@ return function (Database $db): void { ...@@ -16,12 +16,14 @@ return function (Database $db): void {
$exists = $db->selectOne("SELECT id FROM system_config WHERE config_key = ?", [$rule['key']]); $exists = $db->selectOne("SELECT id FROM system_config WHERE config_key = ?", [$rule['key']]);
if (!$exists) { if (!$exists) {
$db->insert('system_config', [ $db->insert('system_config', [
'config_key' => $rule['key'], 'config_key' => $rule['key'],
'config_value' => $rule['value'], 'config_value' => $rule['value'],
'description' => $rule['description'], 'config_type' => 'json',
'is_active' => 1, 'group_name' => 'seasonal',
'created_at' => date('Y-m-d H:i:s'), 'description_ar' => $rule['description'],
'updated_at' => date('Y-m-d H:i:s'), 'is_editable' => 1,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
]); ]);
} }
} }
......
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