diff --git a/application/config/migration.php b/application/config/migration.php index 52637be5..d1869307 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 207; +$config['migration_version'] = 208; /* |-------------------------------------------------------------------------- diff --git a/application/migrations/208_add_indexes_lotw_users.php b/application/migrations/208_add_indexes_lotw_users.php new file mode 100644 index 00000000..20c4dd68 --- /dev/null +++ b/application/migrations/208_add_indexes_lotw_users.php @@ -0,0 +1,38 @@ +db->table_exists('lotw_users')) { + // add an index on callsign if no index exists on that column + $callsignIndex = $this->db->query("SHOW INDEX FROM lotw_users WHERE Column_name = 'callsign'"); + if ($callsignIndex->num_rows() == 0) { + $this->db->query("ALTER TABLE lotw_users ADD INDEX `callsign` (`callsign`)"); + } + + // add an index on lastupload if it doesn't exist + $lastuploadIndex = $this->db->query("SHOW INDEX FROM lotw_users WHERE Column_name = 'lastupload'"); + if ($lastuploadIndex->num_rows() == 0) { + $this->db->query("ALTER TABLE lotw_users ADD INDEX `lastupload` (`lastupload`)"); + } + } + } + + public function down() + { + if ($this->db->table_exists('lotw_users')) { + // drop the indexes we might have created (only if the index name matches) + $li = $this->db->query("SHOW INDEX FROM lotw_users WHERE Key_name = 'lastupload'"); + if ($li->num_rows() > 0) { + $this->db->query("ALTER TABLE lotw_users DROP INDEX `lastupload`"); + } + + $ci = $this->db->query("SHOW INDEX FROM lotw_users WHERE Key_name = 'callsign'"); + if ($ci->num_rows() > 0) { + $this->db->query("ALTER TABLE lotw_users DROP INDEX `callsign`"); + } + } + } +}