Commit 1626311b authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix DROP INDEX IF EXISTS syntax for older MySQL versions

Replace unsupported DROP INDEX IF EXISTS with information_schema check.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 509f2b81
...@@ -23,8 +23,14 @@ return function (\App\Core\Database $db): void { ...@@ -23,8 +23,14 @@ return function (\App\Core\Database $db): void {
} }
} }
$db->raw("ALTER TABLE `{$table}` DROP INDEX IF EXISTS `uk_date_bank`"); $idxBank = $db->selectOne("SELECT 1 FROM information_schema.statistics WHERE table_schema = DATABASE() AND table_name = ? AND index_name = 'uk_date_bank'", [$table]);
$db->raw("ALTER TABLE `{$table}` DROP INDEX IF EXISTS `uk_date_safe`"); if ($idxBank) {
$db->raw("ALTER TABLE `{$table}` DROP INDEX `uk_date_bank`");
}
$idxSafe = $db->selectOne("SELECT 1 FROM information_schema.statistics WHERE table_schema = DATABASE() AND table_name = ? AND index_name = 'uk_date_safe'", [$table]);
if ($idxSafe) {
$db->raw("ALTER TABLE `{$table}` DROP INDEX `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]); $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) { if (!$idx) {
......
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