Skip to content

Commit b4a65a6

Browse files
committed
bug 9453: domain path is not unique value, removed the constraint added during 2.1.8-2.2.2 upgrade
1 parent 24e1553 commit b4a65a6

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

server/src/com/cloud/upgrade/dao/Upgrade222to224.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public void performDataMigration(Connection conn) {
6464
updateGuestOsType(conn);
6565
updateNicsWithMode(conn);
6666
updateUserStatsWithNetwork(conn);
67+
dropIndexIfExists(conn);
6768
}
6869

6970
@Override
@@ -219,4 +220,22 @@ private void updateUserStatsWithNetwork(Connection conn) {
219220
}
220221
}
221222

223+
private void dropIndexIfExists(Connection conn) {
224+
try {
225+
PreparedStatement pstmt = conn.prepareStatement("SHOW INDEX FROM domain WHERE KEY_NAME = 'path'");
226+
ResultSet rs = pstmt.executeQuery();
227+
228+
if (rs.next()) {
229+
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`domain` DROP INDEX `path`");
230+
pstmt.executeUpdate();
231+
s_logger.debug("Unique key 'path' is removed successfully");
232+
}
233+
234+
rs.close();
235+
pstmt.close();
236+
} catch (SQLException e) {
237+
throw new CloudRuntimeException("Unable to drop 'path' index for 'domain' table due to:", e);
238+
}
239+
240+
}
222241
}

setup/db/db/schema-21to22.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ ALTER TABLE `cloud`.`instance_group` ADD CONSTRAINT `fk_instance_group__account_
968968
ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___group_id` FOREIGN KEY `fk_instance_group_vm_map___group_id` (`group_id`) REFERENCES `instance_group` (`id`) ON DELETE CASCADE;
969969
ALTER TABLE `cloud`.`instance_group_vm_map` ADD CONSTRAINT `fk_instance_group_vm_map___instance_id` FOREIGN KEY `fk_instance_group_vm_map___instance_id` (`instance_id`) REFERENCES `user_vm` (`id`) ON DELETE CASCADE;
970970
ALTER TABLE `cloud`.`secondary_storage_vm` MODIFY COLUMN `guid` varchar(255);
971-
ALTER TABLE `cloud`.`domain` MODIFY COLUMN `path` varchar(255) UNIQUE NOT NULL;
971+
ALTER TABLE `cloud`.`domain` MODIFY COLUMN `path` varchar(255) NOT NULL;
972972

973973
ALTER TABLE `cloud`.`ssh_keypairs` ADD CONSTRAINT `fk_ssh_keypairs__account_id` FOREIGN KEY `fk_ssh_keypair__account_id` (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE;
974974
ALTER TABLE `cloud`.`ssh_keypairs` ADD CONSTRAINT `fk_ssh_keypairs__domain_id` FOREIGN KEY `fk_ssh_keypair__domain_id` (`domain_id`) REFERENCES `domain` (`id`) ON DELETE CASCADE;

setup/db/db/schema-222to224.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ ALTER TABLE `cloud`.`host_pod_ref` ADD INDEX `i_host_pod_ref__allocation_state`(
6060
ALTER TABLE `cloud`.`host` ADD COLUMN `allocation_state` varchar(32) NOT NULL DEFAULT 'Enabled';
6161
ALTER TABLE `cloud`.`host` ADD INDEX `i_host__allocation_state`(`allocation_state`);
6262

63-
ALTER TABLE `cloud`.`domain` DROP index `path`;
6463
ALTER TABLE `cloud`.`domain` ADD INDEX `i_domain__path`(`path`);
6564

6665
CREATE TABLE `cloud`.`data_center_details` (

0 commit comments

Comments
 (0)