Commit 40b02ff7ffc41a5c186905f04a3b923e31322f73

Authored by Igor Kulikov
1 parent 7f843f61

Improve upgrade scripts.

1 ---  
2 --- Copyright © 2016-2019 The Thingsboard Authors  
3 ---  
4 --- Licensed under the Apache License, Version 2.0 (the "License");  
5 --- you may not use this file except in compliance with the License.  
6 --- You may obtain a copy of the License at  
7 ---  
8 --- http://www.apache.org/licenses/LICENSE-2.0  
9 ---  
10 --- Unless required by applicable law or agreed to in writing, software  
11 --- distributed under the License is distributed on an "AS IS" BASIS,  
12 --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
13 --- See the License for the specific language governing permissions and  
14 --- limitations under the License.  
15 ---  
16 -  
17 --- distributed under the License is distributed on an "AS IS" BASIS,  
18 --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
19 --- See the License for the specific language governing permissions and  
20 --- limitations under the License.  
21 ---  
22 -  
23 -ALTER TABLE thingsboard.device ADD label text;  
@@ -14,8 +14,6 @@ @@ -14,8 +14,6 @@
14 -- limitations under the License. 14 -- limitations under the License.
15 -- 15 --
16 16
17 -ALTER TABLE device ADD COLUMN label varchar(255);  
18 -  
19 CREATE INDEX IF NOT EXISTS idx_alarm_originator_alarm_type ON alarm(tenant_id, type, originator_type, originator_id); 17 CREATE INDEX IF NOT EXISTS idx_alarm_originator_alarm_type ON alarm(tenant_id, type, originator_type, originator_id);
20 18
21 CREATE INDEX IF NOT EXISTS idx_event_type_entity_id ON event(tenant_id, event_type, entity_type, entity_id); 19 CREATE INDEX IF NOT EXISTS idx_event_type_entity_id ON event(tenant_id, event_type, entity_type, entity_id);
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 package org.thingsboard.server.service.install; 16 package org.thingsboard.server.service.install;
17 17
18 import com.datastax.driver.core.KeyspaceMetadata; 18 import com.datastax.driver.core.KeyspaceMetadata;
  19 +import com.datastax.driver.core.exceptions.InvalidQueryException;
19 import lombok.extern.slf4j.Slf4j; 20 import lombok.extern.slf4j.Slf4j;
20 import org.springframework.beans.factory.annotation.Autowired; 21 import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.beans.factory.annotation.Qualifier; 22 import org.springframework.beans.factory.annotation.Qualifier;
@@ -259,8 +260,11 @@ public class CassandraDatabaseUpgradeService implements DatabaseUpgradeService { @@ -259,8 +260,11 @@ public class CassandraDatabaseUpgradeService implements DatabaseUpgradeService {
259 break; 260 break;
260 case "2.3.1": 261 case "2.3.1":
261 log.info("Updating schema ..."); 262 log.info("Updating schema ...");
262 - schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "2.4.0", SCHEMA_UPDATE_CQL);  
263 - loadCql(schemaUpdateFile); 263 + String updateDeviceTableStmt = "alter table device add label text";
  264 + try {
  265 + cluster.getSession().execute(updateDeviceTableStmt);
  266 + Thread.sleep(2500);
  267 + } catch (InvalidQueryException e) {}
264 log.info("Schema updated."); 268 log.info("Schema updated.");
265 break; 269 break;
266 default: 270 default:
@@ -170,6 +170,9 @@ public class SqlDatabaseUpgradeService implements DatabaseUpgradeService { @@ -170,6 +170,9 @@ public class SqlDatabaseUpgradeService implements DatabaseUpgradeService {
170 log.info("Updating schema ..."); 170 log.info("Updating schema ...");
171 schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "2.4.0", SCHEMA_UPDATE_SQL); 171 schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "2.4.0", SCHEMA_UPDATE_SQL);
172 loadSql(schemaUpdateFile, conn); 172 loadSql(schemaUpdateFile, conn);
  173 + try {
  174 + conn.createStatement().execute("ALTER TABLE device ADD COLUMN label varchar(255)"); //NOSONAR, ignoring because method used to execute thingsboard database upgrade script
  175 + } catch (Exception e) {}
173 log.info("Schema updated."); 176 log.info("Schema updated.");
174 } 177 }
175 break; 178 break;