Skip to content

Commit be765ce

Browse files
committed
CLOUDSTACK-6599: Add the column in Java upgrade path since 4.2 already has the extract template/volume columns
1 parent 48ea9e0 commit be765ce

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

engine/schema/src/com/cloud/upgrade/dao/Upgrade430to440.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,41 @@ public File[] getPrepareScripts() {
6161
public void performDataMigration(Connection conn) {
6262
secondaryIpsAccountAndDomainIdsUpdate(conn);
6363
moveCidrsToTheirOwnTable(conn);
64+
addExtractTemplateAndVolumeColumns(conn);
65+
6466
}
6567

68+
private void addExtractTemplateAndVolumeColumns(Connection conn) {
69+
PreparedStatement pstmt = null;
70+
ResultSet rs = null;
71+
72+
try {
73+
74+
// Add download_url_created, download_url to template_store_ref
75+
pstmt = conn.prepareStatement("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'cloud' AND TABLE_NAME = 'template_store_ref' AND COLUMN_NAME = 'download_url_created'");
76+
rs = pstmt.executeQuery();
77+
if (!rs.next()) {
78+
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`template_store_ref` ADD COLUMN `download_url_created` datetime");
79+
pstmt.executeUpdate();
80+
81+
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`template_store_ref` ADD COLUMN `download_url` varchar(255)");
82+
pstmt.executeUpdate();
83+
}
84+
85+
// Add download_url_created to volume_store_ref - note download_url already exists
86+
pstmt = conn.prepareStatement("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'cloud' AND TABLE_NAME = 'volume_store_ref' AND COLUMN_NAME = 'download_url_created'");
87+
rs = pstmt.executeQuery();
88+
if (!rs.next()) {
89+
pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`volume_store_ref` ADD COLUMN `download_url_created` datetime");
90+
pstmt.executeUpdate();
91+
}
92+
93+
} catch (SQLException e) {
94+
throw new CloudRuntimeException("Adding columns for Extract Template And Volume functionality failed");
95+
}
96+
}
97+
98+
6699

67100
private void secondaryIpsAccountAndDomainIdsUpdate(Connection conn) {
68101
PreparedStatement pstmt = null;

setup/db/db/schema-430to440.sql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,3 @@ alter table `cloud`.`vlan` add column created datetime NULL COMMENT 'date create
17051705
alter table `cloud`.`user_ip_address` drop key public_ip_address;
17061706
alter table `cloud`.`user_ip_address` add UNIQUE KEY public_ip_address (public_ip_address,source_network_id, removed);
17071707

1708-
ALTER TABLE `cloud`.`volume_store_ref` ADD `download_url_created` datetime;
1709-
ALTER TABLE `cloud`.`template_store_ref` ADD `download_url_created` datetime;
1710-
ALTER TABLE `cloud`.`template_store_ref` ADD `download_url` varchar(255);
1711-

0 commit comments

Comments
 (0)