Commit c35eff1cdea289681b68749d5f096e998042cfdf

Authored by Vladyslav_Prykhodko
1 parent 6a93307d

Update database schema

  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 +ALTER TABLE device ADD label text;
  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 +ALTER TABLE device ADD COLUMN label varchar(255);
@@ -111,6 +111,12 @@ public class ThingsboardInstallService { @@ -111,6 +111,12 @@ public class ThingsboardInstallService {
111 111
112 databaseUpgradeService.upgradeDatabase("2.3.0"); 112 databaseUpgradeService.upgradeDatabase("2.3.0");
113 113
  114 + break;
  115 + case "2.3.1":
  116 + log.info("Upgrading ThingsBoard from version 2.3.1 to 2.4.0 ...");
  117 +
  118 + databaseUpgradeService.upgradeDatabase("2.3.1");
  119 +
114 log.info("Updating system data..."); 120 log.info("Updating system data...");
115 121
116 systemDataLoaderService.deleteSystemWidgetBundle("charts"); 122 systemDataLoaderService.deleteSystemWidgetBundle("charts");
@@ -127,7 +133,6 @@ public class ThingsboardInstallService { @@ -127,7 +133,6 @@ public class ThingsboardInstallService {
127 systemDataLoaderService.deleteSystemWidgetBundle("date"); 133 systemDataLoaderService.deleteSystemWidgetBundle("date");
128 134
129 systemDataLoaderService.loadSystemWidgets(); 135 systemDataLoaderService.loadSystemWidgets();
130 - break;  
131 default: 136 default:
132 throw new RuntimeException("Unable to upgrade ThingsBoard, unsupported fromVersion: " + upgradeFromVersion); 137 throw new RuntimeException("Unable to upgrade ThingsBoard, unsupported fromVersion: " + upgradeFromVersion);
133 138
@@ -257,6 +257,12 @@ public class CassandraDatabaseUpgradeService implements DatabaseUpgradeService { @@ -257,6 +257,12 @@ public class CassandraDatabaseUpgradeService implements DatabaseUpgradeService {
257 break; 257 break;
258 case "2.3.0": 258 case "2.3.0":
259 break; 259 break;
  260 + case "2.3.1":
  261 + log.info("Updating schema ...");
  262 + schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "2.4.0", SCHEMA_UPDATE_CQL);
  263 + loadCql(schemaUpdateFile);
  264 + log.info("Schema updated.");
  265 + break;
260 default: 266 default:
261 throw new RuntimeException("Unable to upgrade Cassandra database, unsupported fromVersion: " + fromVersion); 267 throw new RuntimeException("Unable to upgrade Cassandra database, unsupported fromVersion: " + fromVersion);
262 } 268 }
@@ -165,6 +165,14 @@ public class SqlDatabaseUpgradeService implements DatabaseUpgradeService { @@ -165,6 +165,14 @@ public class SqlDatabaseUpgradeService implements DatabaseUpgradeService {
165 log.info("Schema updated."); 165 log.info("Schema updated.");
166 } 166 }
167 break; 167 break;
  168 + case "2.3.1":
  169 + try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) {
  170 + log.info("Updating schema ...");
  171 + schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "2.4.0", SCHEMA_UPDATE_SQL);
  172 + loadSql(schemaUpdateFile, conn);
  173 + log.info("Schema updated.");
  174 + }
  175 + break;
168 default: 176 default:
169 throw new RuntimeException("Unable to upgrade SQL database, unsupported fromVersion: " + fromVersion); 177 throw new RuntimeException("Unable to upgrade SQL database, unsupported fromVersion: " + fromVersion);
170 } 178 }
@@ -20,8 +20,6 @@ import org.thingsboard.server.common.data.id.CustomerId; @@ -20,8 +20,6 @@ import org.thingsboard.server.common.data.id.CustomerId;
20 import org.thingsboard.server.common.data.id.DeviceId; 20 import org.thingsboard.server.common.data.id.DeviceId;
21 import org.thingsboard.server.common.data.id.TenantId; 21 import org.thingsboard.server.common.data.id.TenantId;
22 22
23 -import com.fasterxml.jackson.databind.JsonNode;  
24 -  
25 @EqualsAndHashCode(callSuper = true) 23 @EqualsAndHashCode(callSuper = true)
26 public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implements HasName, HasTenantId, HasCustomerId { 24 public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implements HasName, HasTenantId, HasCustomerId {
27 25
@@ -31,6 +29,7 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen @@ -31,6 +29,7 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen
31 private CustomerId customerId; 29 private CustomerId customerId;
32 private String name; 30 private String name;
33 private String type; 31 private String type;
  32 + private String label;
34 33
35 public Device() { 34 public Device() {
36 super(); 35 super();
@@ -46,6 +45,7 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen @@ -46,6 +45,7 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen
46 this.customerId = device.getCustomerId(); 45 this.customerId = device.getCustomerId();
47 this.name = device.getName(); 46 this.name = device.getName();
48 this.type = device.getType(); 47 this.type = device.getType();
  48 + this.label = device.getLabel();
49 } 49 }
50 50
51 public TenantId getTenantId() { 51 public TenantId getTenantId() {
@@ -81,6 +81,14 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen @@ -81,6 +81,14 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen
81 this.type = type; 81 this.type = type;
82 } 82 }
83 83
  84 + public String getLabel() {
  85 + return label;
  86 + }
  87 +
  88 + public void setLabel(String label) {
  89 + this.label = label;
  90 + }
  91 +
84 @Override 92 @Override
85 public String getSearchText() { 93 public String getSearchText() {
86 return getName(); 94 return getName();
@@ -97,6 +105,8 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen @@ -97,6 +105,8 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen
97 builder.append(name); 105 builder.append(name);
98 builder.append(", type="); 106 builder.append(", type=");
99 builder.append(type); 107 builder.append(type);
  108 + builder.append(", label=");
  109 + builder.append(label);
100 builder.append(", additionalInfo="); 110 builder.append(", additionalInfo=");
101 builder.append(getAdditionalInfo()); 111 builder.append(getAdditionalInfo());
102 builder.append(", createdTime="); 112 builder.append(", createdTime=");
@@ -134,6 +134,7 @@ public class ModelConstants { @@ -134,6 +134,7 @@ public class ModelConstants {
134 public static final String DEVICE_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY; 134 public static final String DEVICE_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY;
135 public static final String DEVICE_NAME_PROPERTY = "name"; 135 public static final String DEVICE_NAME_PROPERTY = "name";
136 public static final String DEVICE_TYPE_PROPERTY = "type"; 136 public static final String DEVICE_TYPE_PROPERTY = "type";
  137 + public static final String DEVICE_LABEL_PROPERTY = "label";
137 public static final String DEVICE_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY; 138 public static final String DEVICE_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY;
138 public static final String DEVICE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "device_by_tenant_and_search_text"; 139 public static final String DEVICE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "device_by_tenant_and_search_text";
139 public static final String DEVICE_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "device_by_tenant_by_type_and_search_text"; 140 public static final String DEVICE_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "device_by_tenant_by_type_and_search_text";
@@ -31,14 +31,7 @@ import org.thingsboard.server.dao.model.type.JsonCodec; @@ -31,14 +31,7 @@ import org.thingsboard.server.dao.model.type.JsonCodec;
31 31
32 import java.util.UUID; 32 import java.util.UUID;
33 33
34 -import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_ADDITIONAL_INFO_PROPERTY;  
35 -import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_COLUMN_FAMILY_NAME;  
36 -import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_CUSTOMER_ID_PROPERTY;  
37 -import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_NAME_PROPERTY;  
38 -import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_TENANT_ID_PROPERTY;  
39 -import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_TYPE_PROPERTY;  
40 -import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY;  
41 -import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; 34 +import static org.thingsboard.server.dao.model.ModelConstants.*;
42 35
43 @Table(name = DEVICE_COLUMN_FAMILY_NAME) 36 @Table(name = DEVICE_COLUMN_FAMILY_NAME)
44 @EqualsAndHashCode 37 @EqualsAndHashCode
@@ -64,6 +57,9 @@ public final class DeviceEntity implements SearchTextEntity<Device> { @@ -64,6 +57,9 @@ public final class DeviceEntity implements SearchTextEntity<Device> {
64 @Column(name = DEVICE_NAME_PROPERTY) 57 @Column(name = DEVICE_NAME_PROPERTY)
65 private String name; 58 private String name;
66 59
  60 + @Column(name = DEVICE_LABEL_PROPERTY)
  61 + private String label;
  62 +
67 @Column(name = SEARCH_TEXT_PROPERTY) 63 @Column(name = SEARCH_TEXT_PROPERTY)
68 private String searchText; 64 private String searchText;
69 65
@@ -86,6 +82,7 @@ public final class DeviceEntity implements SearchTextEntity<Device> { @@ -86,6 +82,7 @@ public final class DeviceEntity implements SearchTextEntity<Device> {
86 } 82 }
87 this.name = device.getName(); 83 this.name = device.getName();
88 this.type = device.getType(); 84 this.type = device.getType();
  85 + this.label = device.getLabel();
89 this.additionalInfo = device.getAdditionalInfo(); 86 this.additionalInfo = device.getAdditionalInfo();
90 } 87 }
91 88
@@ -163,6 +160,7 @@ public final class DeviceEntity implements SearchTextEntity<Device> { @@ -163,6 +160,7 @@ public final class DeviceEntity implements SearchTextEntity<Device> {
163 } 160 }
164 device.setName(name); 161 device.setName(name);
165 device.setType(type); 162 device.setType(type);
  163 + device.setLabel(label);
166 device.setAdditionalInfo(additionalInfo); 164 device.setAdditionalInfo(additionalInfo);
167 return device; 165 return device;
168 } 166 }
@@ -53,6 +53,9 @@ public final class DeviceEntity extends BaseSqlEntity<Device> implements SearchT @@ -53,6 +53,9 @@ public final class DeviceEntity extends BaseSqlEntity<Device> implements SearchT
53 @Column(name = ModelConstants.DEVICE_NAME_PROPERTY) 53 @Column(name = ModelConstants.DEVICE_NAME_PROPERTY)
54 private String name; 54 private String name;
55 55
  56 + @Column(name = ModelConstants.DEVICE_LABEL_PROPERTY)
  57 + private String label;
  58 +
56 @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) 59 @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
57 private String searchText; 60 private String searchText;
58 61
@@ -76,6 +79,7 @@ public final class DeviceEntity extends BaseSqlEntity<Device> implements SearchT @@ -76,6 +79,7 @@ public final class DeviceEntity extends BaseSqlEntity<Device> implements SearchT
76 } 79 }
77 this.name = device.getName(); 80 this.name = device.getName();
78 this.type = device.getType(); 81 this.type = device.getType();
  82 + this.label = device.getLabel();
79 this.additionalInfo = device.getAdditionalInfo(); 83 this.additionalInfo = device.getAdditionalInfo();
80 } 84 }
81 85
@@ -101,6 +105,7 @@ public final class DeviceEntity extends BaseSqlEntity<Device> implements SearchT @@ -101,6 +105,7 @@ public final class DeviceEntity extends BaseSqlEntity<Device> implements SearchT
101 } 105 }
102 device.setName(name); 106 device.setName(name);
103 device.setType(type); 107 device.setType(type);
  108 + device.setLabel(label);
104 device.setAdditionalInfo(additionalInfo); 109 device.setAdditionalInfo(additionalInfo);
105 return device; 110 return device;
106 } 111 }
@@ -157,6 +157,7 @@ CREATE TABLE IF NOT EXISTS thingsboard.device ( @@ -157,6 +157,7 @@ CREATE TABLE IF NOT EXISTS thingsboard.device (
157 customer_id timeuuid, 157 customer_id timeuuid,
158 name text, 158 name text,
159 type text, 159 type text,
  160 + label text,
160 search_text text, 161 search_text text,
161 additional_info text, 162 additional_info text,
162 PRIMARY KEY (id, tenant_id, customer_id, type) 163 PRIMARY KEY (id, tenant_id, customer_id, type)
@@ -117,6 +117,7 @@ CREATE TABLE IF NOT EXISTS device ( @@ -117,6 +117,7 @@ CREATE TABLE IF NOT EXISTS device (
117 customer_id varchar(31), 117 customer_id varchar(31),
118 type varchar(255), 118 type varchar(255),
119 name varchar(255), 119 name varchar(255),
  120 + label varchar(255),
120 search_text varchar(255), 121 search_text varchar(255),
121 tenant_id varchar(31) 122 tenant_id varchar(31)
122 ); 123 );
@@ -347,6 +347,7 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device @@ -347,6 +347,7 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
347 return { 347 return {
348 origEntity: entity, 348 origEntity: entity,
349 name: entity.name, 349 name: entity.name,
  350 + label: entity.label?entity.label:"",
350 entityType: entity.id.entityType, 351 entityType: entity.id.entityType,
351 id: entity.id.id, 352 id: entity.id.id,
352 entityDescription: entity.additionalInfo?entity.additionalInfo.description:"" 353 entityDescription: entity.additionalInfo?entity.additionalInfo.description:""