From 2bd54e2ba5885eb88dfb7fcfd57057cd374f25e2 Mon Sep 17 00:00:00 2001 From: int2001 Date: Fri, 2 Feb 2024 10:45:33 +0000 Subject: [PATCH] Check if index is there --- application/migrations/179_remove_dupidx_lotw.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/application/migrations/179_remove_dupidx_lotw.php b/application/migrations/179_remove_dupidx_lotw.php index 5f575fc2d..1b98759af 100644 --- a/application/migrations/179_remove_dupidx_lotw.php +++ b/application/migrations/179_remove_dupidx_lotw.php @@ -5,10 +5,16 @@ defined('BASEPATH') OR exit('No direct script access allowed'); class Migration_remove_dupidx_lotw extends CI_Migration { public function up() { - $this->db->query("ALTER TABLE lotw_users DROP INDEX id"); + $prefixes_index = $this->db->query("SHOW INDEX FROM lotw_users WHERE Key_name = 'id'")->num_rows(); + if ($prefixes_index == 1) { + $this->db->query("ALTER TABLE lotw_users DROP INDEX id"); + } } public function down(){ - $this->db->query("ALTER TABLE lotw_users ADD UNIQUE INDEX id (id)"); + $prefixes_index = $this->db->query("SHOW INDEX FROM lotw_users WHERE Key_name = 'id'")->num_rows(); + if ($prefixes_index == 0) { + $this->db->query("ALTER TABLE lotw_users ADD UNIQUE INDEX id (id)"); + } } }