You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by pr...@apache.org on 2012/08/22 01:39:11 UTC

[1/3] git commit: [ASFCS40]304 -> 305 DB upgrade merge to 302-> 4.0

Updated Branches:
  refs/heads/master cd0004bb8 -> 0b31a0af6


[ASFCS40]304 -> 305 DB upgrade merge to 302-> 4.0


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/0b31a0af
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/0b31a0af
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/0b31a0af

Branch: refs/heads/master
Commit: 0b31a0af6232e15618214983dfa4659b5dc6797c
Parents: 511e3cb
Author: Prachi Damle <pr...@cloud.com>
Authored: Mon Aug 20 23:07:37 2012 -0700
Committer: Prachi Damle <pr...@cloud.com>
Committed: Tue Aug 21 16:27:57 2012 -0700

----------------------------------------------------------------------
 .../src/com/cloud/upgrade/dao/Upgrade302to40.java  |   35 ++++++++++++++-
 1 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0b31a0af/server/src/com/cloud/upgrade/dao/Upgrade302to40.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/upgrade/dao/Upgrade302to40.java b/server/src/com/cloud/upgrade/dao/Upgrade302to40.java
index 5b7ad0a..198dafd 100644
--- a/server/src/com/cloud/upgrade/dao/Upgrade302to40.java
+++ b/server/src/com/cloud/upgrade/dao/Upgrade302to40.java
@@ -64,7 +64,7 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
     public void performDataMigration(Connection conn) {
         correctVRProviders(conn);
         correctMultiplePhysicaNetworkSetups(conn);
-
+        addHostDetailsUniqueKey(conn);
         addVpcProvider(conn);
         updateRouterNetworkRef(conn);
         fixForeignKeys(conn);
@@ -506,7 +506,38 @@ public class Upgrade302to40 extends Upgrade30xBase implements DbUpgrade {
         }
     }
 
-    
+    private void addHostDetailsUniqueKey(Connection conn) {
+        s_logger.debug("Checking if host_details unique key exists, if not we will add it");
+        PreparedStatement pstmt = null;
+        ResultSet rs = null;
+        try {
+            pstmt = conn.prepareStatement("SHOW INDEX FROM `cloud`.`host_details` WHERE KEY_NAME = 'uk_host_id_name'");
+            rs = pstmt.executeQuery();
+            if (rs.next()) {
+                s_logger.debug("Unique key already exists on host_details - not adding new one");
+            }else{
+                //add the key
+                PreparedStatement pstmtUpdate = conn.prepareStatement("ALTER TABLE `cloud`.`host_details` ADD CONSTRAINT UNIQUE KEY `uk_host_id_name` (`host_id`, `name`)");
+                pstmtUpdate.executeUpdate();
+                s_logger.debug("Unique key did not exist on host_details -  added new one");
+                pstmtUpdate.close();
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Failed to check/update the host_details unique key ", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+
+                if (pstmt != null) {
+                    pstmt.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+
     private void addVpcProvider(Connection conn){
         //Encrypt config params and change category to Hidden
         s_logger.debug("Adding vpc provider to all physical networks in the system");