From 82a5edc9b7d129ce3508d1fc7095f249a4c9beae Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Fri, 22 Aug 2025 16:29:49 +0100 Subject: [PATCH] Add indexes to lotw_users table Introduces migration 208 to add indexes on 'callsign' and 'lastupload' columns in the lotw_users table for improved query performance. Updates migration version to 208. --- application/config/migration.php | 2 +- .../migrations/208_add_indexes_lotw_users.php | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 application/migrations/208_add_indexes_lotw_users.php 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`"); + } + } + } +}