From ae70b9181e758dd7f5d83e227da822e343ba8c3e Mon Sep 17 00:00:00 2001 From: int2001 Date: Fri, 24 May 2024 06:51:42 +0000 Subject: [PATCH] Of course add mig, too --- application/migrations/203_contest_idx.php | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 application/migrations/203_contest_idx.php 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); + } + } + +}