From b0aaf75c3b5cbabde7a4665c5caa8c080cd94c5e 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 Conflicts: server/src/com/cloud/upgrade/dao/Upgrade2213to2214.java --- .../cloud/upgrade/dao/Upgrade2213to2214.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/server/src/com/cloud/upgrade/dao/Upgrade2213to2214.java b/server/src/com/cloud/upgrade/dao/Upgrade2213to2214.java index 9bf7c70a34a..2948cfab15b 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade2213to2214.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade2213to2214.java @@ -143,6 +143,29 @@ public class Upgrade2213to2214 implements DbUpgrade { } catch (SQLException e) { throw new CloudRuntimeException("Unable to insert index for removed column in async_job", 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); + } } }