Refactor interface linking system:

- Remove 'interface_connected_asset_interface' column usage
- Introduce 'asset_interface_links' table for one-to-one connections
- Update add/edit/delete queries and modals to handle new schema
- Exclude already-connected interfaces in dropdowns
- Improve data integrity and simplify linking logic
This commit is contained in:
johnnyq
2025-01-18 13:04:56 -05:00
parent d2b3970a7b
commit 360974d9f4
7 changed files with 454 additions and 181 deletions

View File

@@ -2417,17 +2417,55 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.7.7'");
}
if (CURRENT_DATABASE_VERSION == '1.7.7') {
// Domain history
mysqli_query($mysqli, "CREATE TABLE `domain_history` (`domain_history_id` INT(11) NOT NULL AUTO_INCREMENT , `domain_history_column` VARCHAR(200) NOT NULL , `domain_history_old_value` TEXT NOT NULL , `domain_history_new_value` TEXT NOT NULL , `domain_history_domain_id` INT(11) NOT NULL , `domain_history_modified_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP , PRIMARY KEY (`domain_history_id`)) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;");
if (CURRENT_DATABASE_VERSION == '1.7.7') {
// Domain history
mysqli_query($mysqli, "CREATE TABLE `domain_history` (`domain_history_id` INT(11) NOT NULL AUTO_INCREMENT , `domain_history_column` VARCHAR(200) NOT NULL , `domain_history_old_value` TEXT NOT NULL , `domain_history_new_value` TEXT NOT NULL , `domain_history_domain_id` INT(11) NOT NULL , `domain_history_modified_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP , PRIMARY KEY (`domain_history_id`)) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;");
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.7.8'");
}
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.7.8'");
}
// if (CURRENT_DATABASE_VERSION == '1.7.8') {
// // Insert queries here required to update to DB version 1.7.9
if (CURRENT_DATABASE_VERSION == '1.7.8') {
// Use a seperate table for Interface connections / links. This will make it easier to manage.
$createInterfaceLinksTable = "
CREATE TABLE IF NOT EXISTS `asset_interface_links` (
`interface_link_id` INT AUTO_INCREMENT PRIMARY KEY,
`interface_a_id` INT NOT NULL,
`interface_b_id` INT NOT NULL,
`interface_link_type` VARCHAR(100) NULL,
`interface_link_status` VARCHAR(50) NULL,
`interface_link_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`interface_link_updated_at` DATETIME NULL ON UPDATE CURRENT_TIMESTAMP,
CONSTRAINT `fk_interface_a`
FOREIGN KEY (`interface_a_id`)
REFERENCES `asset_interfaces` (`interface_id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_interface_b`
FOREIGN KEY (`interface_b_id`)
REFERENCES `asset_interfaces` (`interface_id`)
ON DELETE CASCADE
ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
";
mysqli_query($mysqli, $createInterfaceLinksTable) or die(mysqli_error($mysqli));
// Drop the old column from asset_interfaces if it exists
$dropConnectedColumn = "
ALTER TABLE `asset_interfaces`
DROP COLUMN IF EXISTS `interface_connected_asset_interface`
";
mysqli_query($mysqli, $dropConnectedColumn) or die(mysqli_error($mysqli));
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.7.9'");
}
// if (CURRENT_DATABASE_VERSION == '1.7.9') {
// // Insert queries here required to update to DB version 1.8.0
// // Then, update the database to the next sequential version
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.7.9'");
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.8.0'");
// }
} else {