Browse Source

Improve upgrade scripts.

pull/1829/head
Igor Kulikov 7 years ago
parent
commit
40b02ff7ff
  1. 23
      application/src/main/data/upgrade/2.4.0/schema_update.cql
  2. 2
      application/src/main/data/upgrade/2.4.0/schema_update.sql
  3. 8
      application/src/main/java/org/thingsboard/server/service/install/CassandraDatabaseUpgradeService.java
  4. 3
      application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java

23
application/src/main/data/upgrade/2.4.0/schema_update.cql

@ -1,23 +0,0 @@
--
-- Copyright © 2016-2019 The Thingsboard Authors
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
ALTER TABLE thingsboard.device ADD label text;

2
application/src/main/data/upgrade/2.4.0/schema_update.sql

@ -14,8 +14,6 @@
-- limitations under the License.
--
ALTER TABLE device ADD COLUMN label varchar(255);
CREATE INDEX IF NOT EXISTS idx_alarm_originator_alarm_type ON alarm(tenant_id, type, originator_type, originator_id);
CREATE INDEX IF NOT EXISTS idx_event_type_entity_id ON event(tenant_id, event_type, entity_type, entity_id);

8
application/src/main/java/org/thingsboard/server/service/install/CassandraDatabaseUpgradeService.java

@ -16,6 +16,7 @@
package org.thingsboard.server.service.install;
import com.datastax.driver.core.KeyspaceMetadata;
import com.datastax.driver.core.exceptions.InvalidQueryException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@ -259,8 +260,11 @@ public class CassandraDatabaseUpgradeService implements DatabaseUpgradeService {
break;
case "2.3.1":
log.info("Updating schema ...");
schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "2.4.0", SCHEMA_UPDATE_CQL);
loadCql(schemaUpdateFile);
String updateDeviceTableStmt = "alter table device add label text";
try {
cluster.getSession().execute(updateDeviceTableStmt);
Thread.sleep(2500);
} catch (InvalidQueryException e) {}
log.info("Schema updated.");
break;
default:

3
application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseUpgradeService.java

@ -170,6 +170,9 @@ public class SqlDatabaseUpgradeService implements DatabaseUpgradeService {
log.info("Updating schema ...");
schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "2.4.0", SCHEMA_UPDATE_SQL);
loadSql(schemaUpdateFile, conn);
try {
conn.createStatement().execute("ALTER TABLE device ADD COLUMN label varchar(255)"); //NOSONAR, ignoring because method used to execute thingsboard database upgrade script
} catch (Exception e) {}
log.info("Schema updated.");
}
break;

Loading…
Cancel
Save