From 27c0246e7f218b7b337220db4c30dc0a720b43ef Mon Sep 17 00:00:00 2001 From: Nitin Mehta Date: Fri, 30 May 2014 14:53:42 -0700 Subject: [PATCH] CLOUDSTACK-6599: Add the column in Java upgrade path since 4.2 already has the extract template/volume columns (cherry picked from commit be765ce8680564b743a73dd360c590c0e495c204) Conflicts: engine/schema/src/com/cloud/upgrade/dao/Upgrade430to440.java setup/db/db/schema-430to440.sql --- .../cloud/upgrade/dao/Upgrade430to440.java | 33 +++++++++++-------- setup/db/db/schema-430to440.sql | 1 - 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade430to440.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade430to440.java index 51494e7aff6..09ac6fe554f 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade430to440.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade430to440.java @@ -66,26 +66,30 @@ public class Upgrade430to440 implements DbUpgrade { updateVlanUris(conn); } - private void addExtractTemplateAndVolumeColumns(Connection conn) { - try (PreparedStatement selectTemplateInfostmt = conn.prepareStatement("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'cloud' AND TABLE_NAME = 'template_store_ref' AND COLUMN_NAME = 'download_url_created'"); - ResultSet templateInfoResults = selectTemplateInfostmt.executeQuery(); - PreparedStatement addDownloadUrlCreatedToTemplateStorerefstatement = conn.prepareStatement("ALTER TABLE `cloud`.`template_store_ref` ADD COLUMN `download_url_created` datetime"); - PreparedStatement addDownloadUrlToTemplateStorerefstatement = conn.prepareStatement("ALTER TABLE `cloud`.`template_store_ref` ADD COLUMN `download_url` varchar(255)"); - PreparedStatement selectVolumeInfostmt = conn.prepareStatement("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'cloud' AND TABLE_NAME = 'volume_store_ref' AND COLUMN_NAME = 'download_url_created'"); - ResultSet volumeInfoResults = selectVolumeInfostmt.executeQuery(); - PreparedStatement addDownloadUrlCreatedToVolumeStorerefstatement = conn.prepareStatement("ALTER TABLE `cloud`.`volume_store_ref` ADD COLUMN `download_url_created` datetime"); - ) { + private void addExtractTemplateAndVolumeColumns(Connection conn) { + PreparedStatement pstmt = null; + ResultSet rs = null; + + try { // Add download_url_created, download_url to template_store_ref - if (!templateInfoResults.next()) { - addDownloadUrlCreatedToTemplateStorerefstatement.executeUpdate(); - addDownloadUrlToTemplateStorerefstatement.executeUpdate(); + pstmt = conn.prepareStatement("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'cloud' AND TABLE_NAME = 'template_store_ref' AND COLUMN_NAME = 'download_url_created'"); + rs = pstmt.executeQuery(); + if (!rs.next()) { + pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`template_store_ref` ADD COLUMN `download_url_created` datetime"); + pstmt.executeUpdate(); + + pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`template_store_ref` ADD COLUMN `download_url` varchar(255)"); + pstmt.executeUpdate(); } // Add download_url_created to volume_store_ref - note download_url already exists - if (!volumeInfoResults.next()) { - addDownloadUrlCreatedToVolumeStorerefstatement.executeUpdate(); + pstmt = conn.prepareStatement("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'cloud' AND TABLE_NAME = 'volume_store_ref' AND COLUMN_NAME = 'download_url_created'"); + rs = pstmt.executeQuery(); + if (!rs.next()) { + pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`volume_store_ref` ADD COLUMN `download_url_created` datetime"); + pstmt.executeUpdate(); } } catch (SQLException e) { @@ -93,6 +97,7 @@ public class Upgrade430to440 implements DbUpgrade { } } + private void secondaryIpsAccountAndDomainIdsUpdate(Connection conn) { String secondIpsSql = "SELECT id, vmId, network_id, account_id, domain_id, ip4_address FROM `cloud`.`nic_secondary_ips`"; diff --git a/setup/db/db/schema-430to440.sql b/setup/db/db/schema-430to440.sql index 97858714d85..0171faa66f6 100644 --- a/setup/db/db/schema-430to440.sql +++ b/setup/db/db/schema-430to440.sql @@ -2452,7 +2452,6 @@ alter table `cloud`.`vlan` add column created datetime NULL COMMENT 'date create alter table `cloud`.`user_ip_address` drop key public_ip_address; alter table `cloud`.`user_ip_address` add UNIQUE KEY public_ip_address (public_ip_address,source_network_id, removed); - CREATE TABLE `cloud`.`load_balancer_stickiness_policy_details` ( `id` bigint unsigned NOT NULL auto_increment, `lb_policy_id` bigint unsigned NOT NULL COMMENT 'resource id',