mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-3417: Prevent conflict of existed foreign keys of baremetal when upgrade
Now we dropped the keys(if any) then re-add them.
This commit is contained in:
parent
7b783f0df4
commit
7d8f6c7022
|
|
@ -95,6 +95,7 @@ public class Upgrade410to420 implements DbUpgrade {
|
|||
removeFirewallServiceFromSharedNetworkOfferingWithSGService(conn);
|
||||
fix22xKVMSnapshots(conn);
|
||||
addIndexForAlert(conn);
|
||||
fixBaremetalForeignKeys(conn);
|
||||
// storage refactor related migration
|
||||
// TODO: add clean-up scripts to delete the deprecated table.
|
||||
migrateSecondaryStorageToImageStore(conn);
|
||||
|
|
@ -103,6 +104,54 @@ public class Upgrade410to420 implements DbUpgrade {
|
|||
migrateSnapshotStoreRef(conn);
|
||||
}
|
||||
|
||||
private void fixBaremetalForeignKeys(Connection conn) {
|
||||
List<String> keys = new ArrayList<String>();
|
||||
keys.add("fk_external_dhcp_devices_nsp_id");
|
||||
keys.add("fk_external_dhcp_devices_host_id");
|
||||
keys.add("fk_external_dhcp_devices_pod_id");
|
||||
keys.add("fk_external_dhcp_devices_physical_network_id");
|
||||
DbUpgradeUtils.dropKeysIfExist(conn, "baremetal_dhcp_devices", keys, true);
|
||||
|
||||
keys.add("fk_external_pxe_devices_nsp_id");
|
||||
keys.add("fk_external_pxe_devices_host_id");
|
||||
keys.add("fk_external_pxe_devices_physical_network_id");
|
||||
DbUpgradeUtils.dropKeysIfExist(conn, "baremetal_pxe_devices", keys, true);
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
try {
|
||||
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`baremetal_dhcp_devices` ADD CONSTRAINT `fk_external_dhcp_devices_nsp_id` FOREIGN KEY (`nsp_id`) REFERENCES `physical_network_service_providers` (`id`) ON DELETE CASCADE");
|
||||
pstmt.executeUpdate();
|
||||
pstmt.close();
|
||||
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`baremetal_dhcp_devices` ADD CONSTRAINT `fk_external_dhcp_devices_host_id` FOREIGN KEY (`host_id`) REFERENCES `host`(`id`) ON DELETE CASCADE");
|
||||
pstmt.executeUpdate();
|
||||
pstmt.close();
|
||||
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`baremetal_dhcp_devices` ADD CONSTRAINT `fk_external_dhcp_devices_pod_id` FOREIGN KEY (`pod_id`) REFERENCES `host_pod_ref`(`id`) ON DELETE CASCADE");
|
||||
pstmt.executeUpdate();
|
||||
pstmt.close();
|
||||
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`baremetal_dhcp_devices` ADD CONSTRAINT `fk_external_dhcp_devices_physical_network_id` FOREIGN KEY (`physical_network_id`) REFERENCES `physical_network`(`id`) ON DELETE CASCADE");
|
||||
pstmt.executeUpdate();
|
||||
pstmt.close();
|
||||
s_logger.debug("Added foreign keys for table baremetal_dhcp_devices");
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to add foreign keys to baremetal_dhcp_devices table", e);
|
||||
}
|
||||
|
||||
try {
|
||||
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`baremetal_pxe_devices` ADD CONSTRAINT `fk_external_pxe_devices_nsp_id` FOREIGN KEY (`nsp_id`) REFERENCES `physical_network_service_providers` (`id`) ON DELETE CASCADE");
|
||||
pstmt.executeUpdate();
|
||||
pstmt.close();
|
||||
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`baremetal_pxe_devices` ADD CONSTRAINT `fk_external_pxe_devices_host_id` FOREIGN KEY (`host_id`) REFERENCES `host`(`id`) ON DELETE CASCADE");
|
||||
pstmt.executeUpdate();
|
||||
pstmt.close();
|
||||
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`baremetal_pxe_devices` ADD CONSTRAINT `fk_external_pxe_devices_physical_network_id` FOREIGN KEY (`physical_network_id`) REFERENCES `physical_network`(`id`) ON DELETE CASCADE");
|
||||
pstmt.executeUpdate();
|
||||
pstmt.close();
|
||||
s_logger.debug("Added foreign keys for table baremetal_pxe_devices");
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to add foreign keys to baremetal_pxe_devices table", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void addIndexForAlert(Connection conn) {
|
||||
|
||||
//First drop if it exists. (Due to patches shipped to customers some will have the index and some wont.)
|
||||
|
|
|
|||
Loading…
Reference in New Issue