2025-08-11 21:50:56 +08:00
|
|
|
<?php
|
|
|
|
|
|
2025-08-18 21:07:43 +08:00
|
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
2025-08-11 21:50:56 +08:00
|
|
|
|
2025-08-18 21:07:43 +08:00
|
|
|
class Migration_add_workable_dxcc_indexes extends CI_Migration
|
|
|
|
|
{
|
2025-08-11 21:50:56 +08:00
|
|
|
|
|
|
|
|
public function up()
|
|
|
|
|
{
|
|
|
|
|
// Add composite index for workable DXCC queries
|
|
|
|
|
// This will greatly improve performance for COL_COUNTRY + station_id + COL_PROP_MODE queries
|
|
|
|
|
$this->db->db_debug = false;
|
2025-08-18 21:07:43 +08:00
|
|
|
|
2025-08-11 21:50:56 +08:00
|
|
|
// Check if index already exists
|
2025-08-18 21:07:43 +08:00
|
|
|
$index_exists = $this->db->query("SHOW INDEX FROM " . $this->config->item('table_name') . " WHERE Key_name = 'idx_workable_dxcc'")->num_rows();
|
|
|
|
|
|
2025-08-11 21:50:56 +08:00
|
|
|
if ($index_exists == 0) {
|
2025-08-18 21:07:43 +08:00
|
|
|
$sql = "ALTER TABLE " . $this->config->item('table_name') . " ADD INDEX `idx_workable_dxcc` (`COL_COUNTRY`, `station_id`, `COL_PROP_MODE`)";
|
2025-08-11 21:50:56 +08:00
|
|
|
$this->db->query($sql);
|
|
|
|
|
}
|
2025-08-18 21:07:43 +08:00
|
|
|
|
2025-08-11 21:50:56 +08:00
|
|
|
// Add index for confirmation status columns
|
2025-08-18 21:07:43 +08:00
|
|
|
$conf_index_exists = $this->db->query("SHOW INDEX FROM " . $this->config->item('table_name') . " WHERE Key_name = 'idx_qsl_confirmations'")->num_rows();
|
|
|
|
|
|
2025-08-11 21:50:56 +08:00
|
|
|
if ($conf_index_exists == 0) {
|
2025-08-18 21:07:43 +08:00
|
|
|
$sql = "ALTER TABLE " . $this->config->item('table_name') . " ADD INDEX `idx_qsl_confirmations` (`COL_QSL_RCVD`, `COL_LOTW_QSL_RCVD`, `COL_EQSL_QSL_RCVD`, `COL_QRZCOM_QSO_DOWNLOAD_STATUS`)";
|
2025-08-11 21:50:56 +08:00
|
|
|
$this->db->query($sql);
|
|
|
|
|
}
|
2025-08-18 21:07:43 +08:00
|
|
|
|
2025-08-11 21:50:56 +08:00
|
|
|
$this->db->db_debug = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function down()
|
|
|
|
|
{
|
|
|
|
|
$this->db->db_debug = false;
|
2025-08-18 21:07:43 +08:00
|
|
|
|
2025-08-11 21:50:56 +08:00
|
|
|
// Drop the indexes if they exist
|
2025-08-18 21:07:43 +08:00
|
|
|
$index_exists = $this->db->query("SHOW INDEX FROM " . $this->config->item('table_name') . " WHERE Key_name = 'idx_workable_dxcc'")->num_rows();
|
2025-08-11 21:50:56 +08:00
|
|
|
if ($index_exists > 0) {
|
2025-08-18 21:07:43 +08:00
|
|
|
$this->db->query("ALTER TABLE " . $this->config->item('table_name') . " DROP INDEX `idx_workable_dxcc`");
|
2025-08-11 21:50:56 +08:00
|
|
|
}
|
2025-08-18 21:07:43 +08:00
|
|
|
|
|
|
|
|
$conf_index_exists = $this->db->query("SHOW INDEX FROM " . $this->config->item('table_name') . " WHERE Key_name = 'idx_qsl_confirmations'")->num_rows();
|
2025-08-11 21:50:56 +08:00
|
|
|
if ($conf_index_exists > 0) {
|
2025-08-18 21:07:43 +08:00
|
|
|
$this->db->query("ALTER TABLE " . $this->config->item('table_name') . " DROP INDEX `idx_qsl_confirmations`");
|
2025-08-11 21:50:56 +08:00
|
|
|
}
|
2025-08-18 21:07:43 +08:00
|
|
|
|
2025-08-11 21:50:56 +08:00
|
|
|
$this->db->db_debug = true;
|
|
|
|
|
}
|
|
|
|
|
}
|