diff --git a/application/migrations/203_contest_idx.php b/application/migrations/203_contest_idx.php new file mode 100644 index 000000000..afd55f474 --- /dev/null +++ b/application/migrations/203_contest_idx.php @@ -0,0 +1,33 @@ +add_ix('contest','idx_contest_adifname','`adifname`'); + } + + public function down() { + $this->rm_ix('contest','idx_contest_adifname'); + } + + private function add_ix($table_name,$index,$cols) { + $ix_exist = $this->db->query("SHOW INDEX FROM ".$table_name." WHERE Key_name = '".$index."'")->num_rows(); + if ($ix_exist == 0) { + $sql = "ALTER TABLE ".$table_name." ADD INDEX `".$index."` (".$cols.");"; + $this->db->query($sql); + } + } + + private function rm_ix($table_name,$index) { + $ix_exist = $this->db->query("SHOW INDEX FROM ".$table_name." WHERE Key_name = '".$index."'")->num_rows(); + if ($ix_exist >= 1) { + $sql = "ALTER TABLE ".$table_name." DROP INDEX `".$index."`;"; + $this->db->query($sql); + } + } + +}