Check if index is there

This commit is contained in:
int2001
2024-02-02 10:45:33 +00:00
parent 4fc8a75e3c
commit 2bd54e2ba5

View File

@@ -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)");
}
}
}