You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ya...@apache.org on 2013/07/10 01:36:57 UTC
git commit: updated refs/heads/master to 7d8f6c7
Updated Branches:
refs/heads/master 7b783f0df -> 7d8f6c702
CLOUDSTACK-3417: Prevent conflict of existed foreign keys of baremetal when upgrade
Now we dropped the keys(if any) then re-add them.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/7d8f6c70
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/7d8f6c70
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/7d8f6c70
Branch: refs/heads/master
Commit: 7d8f6c70221fddd9227f7270b05245c2dd973d5b
Parents: 7b783f0
Author: Sheng Yang <sh...@citrix.com>
Authored: Tue Jul 9 16:34:51 2013 -0700
Committer: Sheng Yang <sh...@citrix.com>
Committed: Tue Jul 9 16:36:52 2013 -0700
----------------------------------------------------------------------
.../com/cloud/upgrade/dao/Upgrade410to420.java | 49 ++++++++++++++++++++
1 file changed, 49 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7d8f6c70/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
index 3073324..aa1a55c 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -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.)