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 14 -- limitations under the License.
15 15 --
16 16
17   -ALTER TABLE device ADD COLUMN label varchar(255);
18   -
19 17 CREATE INDEX IF NOT EXISTS idx_alarm_originator_alarm_type ON alarm(tenant_id, type, originator_type, originator_id);
20 18
21 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 16 package org.thingsboard.server.service.install;
17 17
18 18 import com.datastax.driver.core.KeyspaceMetadata;
  19 +import com.datastax.driver.core.exceptions.InvalidQueryException;
19 20 import lombok.extern.slf4j.Slf4j;
20 21 import org.springframework.beans.factory.annotation.Autowired;
21 22 import org.springframework.beans.factory.annotation.Qualifier;
... ... @@ -259,8 +260,11 @@ public class CassandraDatabaseUpgradeService implements DatabaseUpgradeService {
259 260 break;
260 261 case "2.3.1":
261 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 268 log.info("Schema updated.");
265 269 break;
266 270 default:
... ...
... ... @@ -170,6 +170,9 @@ public class SqlDatabaseUpgradeService implements DatabaseUpgradeService {
170 170 log.info("Updating schema ...");
171 171 schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "2.4.0", SCHEMA_UPDATE_SQL);
172 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 176 log.info("Schema updated.");
174 177 }
175 178 break;
... ...