Skip to content

Commit 8085a3e

Browse files
committed
remove unique key constraint from cloud_usage.usage_vm_instance table
1 parent 6f1aa96 commit 8085a3e

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
import javax.inject.Inject;
3535

36-
import com.cloud.upgrade.dao.Upgrade42020to42030;
3736
import com.cloud.utils.FileUtil;
3837
import org.apache.cloudstack.utils.CloudStackVersion;
3938
import org.apache.commons.lang3.StringUtils;
@@ -90,6 +89,8 @@
9089
import com.cloud.upgrade.dao.Upgrade41900to41910;
9190
import com.cloud.upgrade.dao.Upgrade41910to42000;
9291
import com.cloud.upgrade.dao.Upgrade42000to42010;
92+
import com.cloud.upgrade.dao.Upgrade42020to42030;
93+
import com.cloud.upgrade.dao.Upgrade42030to42040;
9394
import com.cloud.upgrade.dao.Upgrade420to421;
9495
import com.cloud.upgrade.dao.Upgrade421to430;
9596
import com.cloud.upgrade.dao.Upgrade430to440;
@@ -238,6 +239,7 @@ public DatabaseUpgradeChecker() {
238239
.next("4.19.1.0", new Upgrade41910to42000())
239240
.next("4.20.0.0", new Upgrade42000to42010())
240241
.next("4.20.2.0", new Upgrade42020to42030())
242+
.next("4.20.3.0", new Upgrade42030to42040())
241243
.build();
242244
}
243245

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
import java.util.ArrayList;
22+
import java.util.List;
23+
24+
import com.cloud.utils.exception.CloudRuntimeException;
25+
26+
public class Upgrade42030to42040 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate {
27+
28+
@Override
29+
public String[] getUpgradableVersionRange() {
30+
return new String[]{"4.20.3.0", "4.20.4.0"};
31+
}
32+
33+
@Override
34+
public String getUpgradedVersion() {
35+
return "4.20.4.0";
36+
}
37+
38+
@Override
39+
public boolean supportsRollingUpgrade() {
40+
return false;
41+
}
42+
43+
@Override
44+
public InputStream[] getPrepareScripts() {
45+
return null;
46+
}
47+
48+
@Override
49+
public void performDataMigration(Connection conn) {
50+
final List<String> indexList = new ArrayList<String>();
51+
logger.debug("Dropping index vm_instance_id from usage_vm_instance table if it exists");
52+
indexList.add("vm_instance_id");
53+
DbUpgradeUtils.dropKeysIfExist(conn, "cloud_usage.vm_instance_id", indexList, false);
54+
}
55+
56+
@Override
57+
public InputStream[] getCleanupScripts() {
58+
return null;
59+
}
60+
}

setup/db/create-schema-premium.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ CREATE TABLE `cloud_usage`.`usage_vm_instance` (
7171
`hypervisor_type` varchar(255),
7272
`start_date` DATETIME NOT NULL,
7373
`end_date` DATETIME NULL,
74-
UNIQUE KEY (`vm_instance_id`, `usage_type`, `start_date`)
7574
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
7675

7776
ALTER TABLE `cloud_usage`.`usage_vm_instance` ADD INDEX `i_usage_vm_instance__account_id`(`account_id`);

0 commit comments

Comments
 (0)