Skip to content

Commit b0aaf75

Browse files
author
kishan
committed
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
1 parent 6d2e75d commit b0aaf75

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎server/src/com/cloud/upgrade/dao/Upgrade2213to2214.java‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,29 @@ private void fixIndexes(Connection conn) {
143143
} catch (SQLException e) {
144144
throw new CloudRuntimeException("Unable to insert index for removed column in async_job", e);
145145
}
146+
147+
keys = new ArrayList<String>();
148+
keys.add("fk_ssh_keypair__account_id");
149+
keys.add("fk_ssh_keypair__domain_id");
150+
keys.add("fk_ssh_keypairs__account_id");
151+
keys.add("fk_ssh_keypairs__domain_id");
152+
DbUpgradeUtils.dropKeysIfExist(conn, "ssh_keypairs", keys, true);
153+
154+
try {
155+
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");
156+
pstmt.executeUpdate();
157+
pstmt.close();
158+
} catch (SQLException e) {
159+
throw new CloudRuntimeException("Unable to execute ssh_keypairs table update for adding account_id foreign key", e);
160+
}
161+
162+
try {
163+
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");
164+
pstmt.executeUpdate();
165+
pstmt.close();
166+
} catch (SQLException e) {
167+
throw new CloudRuntimeException("Unable to execute ssh_keypairs table update for adding domain_id foreign key", e);
168+
}
146169

147170
}
148171
}

0 commit comments

Comments
 (0)