You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2012/08/22 00:39:54 UTC
[1/6] git commit: CS-16111 - DB upgrade; fixed foreign keys names
Updated Branches:
refs/heads/master aa5aa30b4 -> cd0004bb8
CS-16111 - DB upgrade; fixed foreign keys names
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/cd0004bb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/cd0004bb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/cd0004bb
Branch: refs/heads/master
Commit: cd0004bb86cde5ff7fe09c05945b60d0fd6c967b
Parents: e252de4
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Tue Aug 21 15:38:17 2012 -0700
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Tue Aug 21 15:38:17 2012 -0700
----------------------------------------------------------------------
.../src/com/cloud/upgrade/dao/Upgrade302to40.java | 42 +++++++++++++++
1 files changed, 42 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/cd0004bb/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 dafb978..98daaa0 100644
--- a/server/src/com/cloud/upgrade/dao/Upgrade302to40.java
+++ b/server/src/com/cloud/upgrade/dao/Upgrade302to40.java
@@ -22,6 +22,8 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.log4j.Logger;
@@ -60,6 +62,7 @@ public class Upgrade302to40 implements DbUpgrade {
public void performDataMigration(Connection conn) {
addVpcProvider(conn);
updateRouterNetworkRef(conn);
+ fixForeignKeys(conn);
}
@Override
@@ -176,4 +179,43 @@ public class Upgrade302to40 implements DbUpgrade {
}
s_logger.debug("Done updating router/network references");
}
+
+
+ private void fixForeignKeys(Connection conn) {
+ //Drop the keys (if exist)
+ List<String> keys = new ArrayList<String>();
+ keys.add("fk_ssh_keypair__account_id");
+ keys.add("fk_ssh_keypair__domain_id");
+ keys.add("fk_ssh_keypairs__account_id");
+ keys.add("fk_ssh_keypairs__domain_id");
+ DbUpgradeUtils.dropKeysIfExist(conn, "ssh_keypairs", keys, true);
+
+ keys = new ArrayList<String>();
+ keys.add("fk_ssh_keypair__account_id");
+ keys.add("fk_ssh_keypair__domain_id");
+ keys.add("fk_ssh_keypairs__account_id");
+ keys.add("fk_ssh_keypairs__domain_id");
+ DbUpgradeUtils.dropKeysIfExist(conn, "ssh_keypairs", keys, false);
+
+ //insert the keys anew
+ try {
+ PreparedStatement pstmt; pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`ssh_keypairs` ADD " +
+ "CONSTRAINT `fk_ssh_keypair__account_id` FOREIGN KEY `fk_ssh_keypair__account_id` (`account_id`)" +
+ " REFERENCES `account` (`id`) ON DELETE CASCADE");
+ pstmt.executeUpdate();
+ pstmt.close();
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("Unable to execute ssh_keypairs table update for adding account_id foreign key", e);
+ }
+
+ try {
+ PreparedStatement pstmt; pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`ssh_keypairs` ADD CONSTRAINT" +
+ " `fk_ssh_keypair__domain_id` FOREIGN KEY `fk_ssh_keypair__domain_id` (`domain_id`) " +
+ "REFERENCES `domain` (`id`) ON DELETE CASCADE");
+ pstmt.executeUpdate();
+ pstmt.close();
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("Unable to execute ssh_keypairs table update for adding domain_id foreign key", e);
+ }
+ }
}