Skip to content

Commit 568cb35

Browse files
committed
fix db upgrade for 4.22
1 parent 21d844b commit 568cb35

File tree

5 files changed

+132
-7
lines changed

5 files changed

+132
-7
lines changed

engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
import com.cloud.upgrade.dao.Upgrade42000to42010;
9292
import com.cloud.upgrade.dao.Upgrade42010to42100;
9393
import com.cloud.upgrade.dao.Upgrade42100to42200;
94+
import com.cloud.upgrade.dao.Upgrade42200to42210;
9495
import com.cloud.upgrade.dao.Upgrade420to421;
9596
import com.cloud.upgrade.dao.Upgrade421to430;
9697
import com.cloud.upgrade.dao.Upgrade430to440;
@@ -236,6 +237,7 @@ public DatabaseUpgradeChecker() {
236237
.next("4.20.0.0", new Upgrade42000to42010())
237238
.next("4.20.1.0", new Upgrade42010to42100())
238239
.next("4.21.0.0", new Upgrade42100to42200())
240+
.next("4.22.0.0", new Upgrade42200to42210())
239241
.build();
240242
}
241243

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.upgrade.dao;
18+
19+
import java.io.InputStream;
20+
import java.sql.Connection;
21+
22+
import com.cloud.upgrade.SystemVmTemplateRegistration;
23+
import com.cloud.utils.exception.CloudRuntimeException;
24+
25+
public class Upgrade42200to42210 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate {
26+
private SystemVmTemplateRegistration systemVmTemplateRegistration;
27+
28+
@Override
29+
public String[] getUpgradableVersionRange() {
30+
return new String[] {"4.22.0.0", "4.22.1.0"};
31+
}
32+
33+
@Override
34+
public String getUpgradedVersion() {
35+
return "4.22.1.0";
36+
}
37+
38+
@Override
39+
public boolean supportsRollingUpgrade() {
40+
return false;
41+
}
42+
43+
@Override
44+
public InputStream[] getPrepareScripts() {
45+
final String scriptFile = "META-INF/db/schema-42200to42210.sql";
46+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
47+
if (script == null) {
48+
throw new CloudRuntimeException("Unable to find " + scriptFile);
49+
}
50+
51+
return new InputStream[] {script};
52+
}
53+
54+
@Override
55+
public void performDataMigration(Connection conn) {
56+
}
57+
58+
@Override
59+
public InputStream[] getCleanupScripts() {
60+
final String scriptFile = "META-INF/db/schema-42200to42210-cleanup.sql";
61+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
62+
if (script == null) {
63+
throw new CloudRuntimeException("Unable to find " + scriptFile);
64+
}
65+
66+
return new InputStream[] {script};
67+
}
68+
69+
private void initSystemVmTemplateRegistration() {
70+
systemVmTemplateRegistration = new SystemVmTemplateRegistration("");
71+
}
72+
73+
@Override
74+
public void updateSystemVmTemplates(Connection conn) {
75+
logger.debug("Updating System Vm template IDs");
76+
initSystemVmTemplateRegistration();
77+
try {
78+
systemVmTemplateRegistration.updateSystemVmTemplates(conn);
79+
} catch (Exception e) {
80+
throw new CloudRuntimeException("Failed to find / register SystemVM template(s)", e);
81+
}
82+
}
83+
}

engine/schema/src/main/resources/META-INF/db/schema-42100to42200.sql

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.ldap_configuration', 'uuid', 'VARCHA
4141
-- Populate uuid for existing rows where uuid is NULL or empty
4242
UPDATE `cloud`.`ldap_configuration` SET uuid = UUID() WHERE uuid IS NULL OR uuid = '';
4343

44-
-- Add vm_id column to usage_event table for volume usage events
45-
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.usage_event','vm_id', 'bigint UNSIGNED NULL COMMENT "VM ID associated with volume usage events"');
46-
CALL `cloud_usage`.`IDEMPOTENT_ADD_COLUMN`('cloud_usage.usage_event','vm_id', 'bigint UNSIGNED NULL COMMENT "VM ID associated with volume usage events"');
47-
48-
-- Add vm_id column to cloud_usage.usage_volume table
49-
CALL `cloud_usage`.`IDEMPOTENT_ADD_COLUMN`('cloud_usage.usage_volume','vm_id', 'bigint UNSIGNED NULL COMMENT "VM ID associated with the volume usage"');
50-
5144
-- Add the column cross_zone_instance_creation to cloud.backup_repository. if enabled it means that new Instance can be created on all Zones from Backups on this Repository.
5245
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.backup_repository', 'cross_zone_instance_creation', 'TINYINT(1) DEFAULT NULL COMMENT ''Backup Repository can be used for disaster recovery on another zone''');
5346

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
--;
19+
-- Schema upgrade cleanup from 4.22.0.0 to 4.22.1.0
20+
--;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
--;
19+
-- Schema upgrade from 4.22.0.0 to 4.22.1.0
20+
--;
21+
22+
-- Add vm_id column to usage_event table for volume usage events
23+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.usage_event','vm_id', 'bigint UNSIGNED NULL COMMENT "VM ID associated with volume usage events"');
24+
CALL `cloud_usage`.`IDEMPOTENT_ADD_COLUMN`('cloud_usage.usage_event','vm_id', 'bigint UNSIGNED NULL COMMENT "VM ID associated with volume usage events"');
25+
26+
-- Add vm_id column to cloud_usage.usage_volume table
27+
CALL `cloud_usage`.`IDEMPOTENT_ADD_COLUMN`('cloud_usage.usage_volume','vm_id', 'bigint UNSIGNED NULL COMMENT "VM ID associated with the volume usage"');

0 commit comments

Comments
 (0)