From a0f48786d1d3fec121c978d6bedf98c408798c10 Mon Sep 17 00:00:00 2001 From: kishan Date: Mon, 6 Feb 2012 13:59:47 +0530 Subject: [PATCH] Bug 13454: Remove foriegn keys in ssh_keypairs table and again with correct constraint name Status 13454: resolved fixed Reviewed-By: Nitin --- .../cloud/upgrade/dao/Upgrade2213to2214.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/server/src/com/cloud/upgrade/dao/Upgrade2213to2214.java b/server/src/com/cloud/upgrade/dao/Upgrade2213to2214.java index b2051be2e2b..74fd14545a6 100755 --- a/server/src/com/cloud/upgrade/dao/Upgrade2213to2214.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade2213to2214.java @@ -81,29 +81,29 @@ public class Upgrade2213to2214 implements DbUpgrade { throw new CloudRuntimeException("Unable to execute usage_event table update", e); } - if (DbUpgradeUtils.dropKeysIfExistAndReturnValue(conn, "ssh_keypairs", "fk_ssh_keypair__account_id", false)) { - PreparedStatement pstmt; - try { - pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`ssh_keypairs` ADD KEY `fk_ssh_keypairs__account_id`(`account_id`)"); - pstmt.executeUpdate(); - pstmt.close(); - } catch (SQLException e) { - throw new CloudRuntimeException("Unable to execute ssh_keypairs table update", e); - } + keys = new ArrayList(); + 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); + + try { + PreparedStatement pstmt; pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`ssh_keypairs` ADD CONSTRAINT `fk_ssh_keypairs__account_id` FOREIGN KEY `fk_ssh_keypairs__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_keypairs__domain_id` FOREIGN KEY `fk_ssh_keypairs__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); + } - if (DbUpgradeUtils.dropKeysIfExistAndReturnValue(conn, "ssh_keypairs", "fk_ssh_keypair__domain_id", false)) { - PreparedStatement pstmt; - try { - pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`ssh_keypairs` ADD KEY `fk_ssh_keypairs__domain_id`(`domain_id`)"); - pstmt.executeUpdate(); - pstmt.close(); - } catch (SQLException e) { - throw new CloudRuntimeException("Unable to execute ssh_keypairs table update", e); - } - - } //In cloud_usage DB, drop i_usage_event__created key (if exists) and re-add it again keys = new ArrayList();