Update database schema
This commit is contained in:
		
							parent
							
								
									6a93307d28
								
							
						
					
					
						commit
						c35eff1cde
					
				
							
								
								
									
										17
									
								
								application/src/main/data/upgrade/2.4.0/schema_update.cql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								application/src/main/data/upgrade/2.4.0/schema_update.cql
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
			
		||||
--
 | 
			
		||||
-- 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.
 | 
			
		||||
--
 | 
			
		||||
 | 
			
		||||
ALTER TABLE device ADD label text;
 | 
			
		||||
							
								
								
									
										17
									
								
								application/src/main/data/upgrade/2.4.0/schema_update.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								application/src/main/data/upgrade/2.4.0/schema_update.sql
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
			
		||||
--
 | 
			
		||||
-- 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.
 | 
			
		||||
--
 | 
			
		||||
 | 
			
		||||
ALTER TABLE device ADD COLUMN label varchar(255);
 | 
			
		||||
@ -111,6 +111,12 @@ public class ThingsboardInstallService {
 | 
			
		||||
 | 
			
		||||
                        databaseUpgradeService.upgradeDatabase("2.3.0");
 | 
			
		||||
 | 
			
		||||
                        break;
 | 
			
		||||
                    case "2.3.1":
 | 
			
		||||
                        log.info("Upgrading ThingsBoard from version 2.3.1 to 2.4.0 ...");
 | 
			
		||||
 | 
			
		||||
                        databaseUpgradeService.upgradeDatabase("2.3.1");
 | 
			
		||||
 | 
			
		||||
                        log.info("Updating system data...");
 | 
			
		||||
 | 
			
		||||
                        systemDataLoaderService.deleteSystemWidgetBundle("charts");
 | 
			
		||||
@ -127,7 +133,6 @@ public class ThingsboardInstallService {
 | 
			
		||||
                        systemDataLoaderService.deleteSystemWidgetBundle("date");
 | 
			
		||||
 | 
			
		||||
                        systemDataLoaderService.loadSystemWidgets();
 | 
			
		||||
                        break;
 | 
			
		||||
                    default:
 | 
			
		||||
                        throw new RuntimeException("Unable to upgrade ThingsBoard, unsupported fromVersion: " + upgradeFromVersion);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -257,6 +257,12 @@ public class CassandraDatabaseUpgradeService implements DatabaseUpgradeService {
 | 
			
		||||
                break;
 | 
			
		||||
            case "2.3.0":
 | 
			
		||||
                break;
 | 
			
		||||
            case "2.3.1":
 | 
			
		||||
                log.info("Updating schema ...");
 | 
			
		||||
                schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "2.4.0", SCHEMA_UPDATE_CQL);
 | 
			
		||||
                loadCql(schemaUpdateFile);
 | 
			
		||||
                log.info("Schema updated.");
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
                throw new RuntimeException("Unable to upgrade Cassandra database, unsupported fromVersion: " + fromVersion);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -165,6 +165,14 @@ public class SqlDatabaseUpgradeService implements DatabaseUpgradeService {
 | 
			
		||||
                    log.info("Schema updated.");
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
            case "2.3.1":
 | 
			
		||||
                try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) {
 | 
			
		||||
                    log.info("Updating schema ...");
 | 
			
		||||
                    schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "2.4.0", SCHEMA_UPDATE_SQL);
 | 
			
		||||
                    loadSql(schemaUpdateFile, conn);
 | 
			
		||||
                    log.info("Schema updated.");
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
                throw new RuntimeException("Unable to upgrade SQL database, unsupported fromVersion: " + fromVersion);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -20,8 +20,6 @@ import org.thingsboard.server.common.data.id.CustomerId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.DeviceId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.databind.JsonNode;
 | 
			
		||||
 | 
			
		||||
@EqualsAndHashCode(callSuper = true)
 | 
			
		||||
public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implements HasName, HasTenantId, HasCustomerId {
 | 
			
		||||
 | 
			
		||||
@ -31,6 +29,7 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen
 | 
			
		||||
    private CustomerId customerId;
 | 
			
		||||
    private String name;
 | 
			
		||||
    private String type;
 | 
			
		||||
    private String label;
 | 
			
		||||
 | 
			
		||||
    public Device() {
 | 
			
		||||
        super();
 | 
			
		||||
@ -46,6 +45,7 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen
 | 
			
		||||
        this.customerId = device.getCustomerId();
 | 
			
		||||
        this.name = device.getName();
 | 
			
		||||
        this.type = device.getType();
 | 
			
		||||
        this.label = device.getLabel();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TenantId getTenantId() {
 | 
			
		||||
@ -81,6 +81,14 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen
 | 
			
		||||
        this.type = type;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getLabel() {
 | 
			
		||||
        return label;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setLabel(String label) {
 | 
			
		||||
        this.label = label;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getSearchText() {
 | 
			
		||||
        return getName();
 | 
			
		||||
@ -97,6 +105,8 @@ public class Device extends SearchTextBasedWithAdditionalInfo<DeviceId> implemen
 | 
			
		||||
        builder.append(name);
 | 
			
		||||
        builder.append(", type=");
 | 
			
		||||
        builder.append(type);
 | 
			
		||||
        builder.append(", label=");
 | 
			
		||||
        builder.append(label);
 | 
			
		||||
        builder.append(", additionalInfo=");
 | 
			
		||||
        builder.append(getAdditionalInfo());
 | 
			
		||||
        builder.append(", createdTime=");
 | 
			
		||||
 | 
			
		||||
@ -134,6 +134,7 @@ public class ModelConstants {
 | 
			
		||||
    public static final String DEVICE_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY;
 | 
			
		||||
    public static final String DEVICE_NAME_PROPERTY = "name";
 | 
			
		||||
    public static final String DEVICE_TYPE_PROPERTY = "type";
 | 
			
		||||
    public static final String DEVICE_LABEL_PROPERTY = "label";
 | 
			
		||||
    public static final String DEVICE_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY;
 | 
			
		||||
    public static final String DEVICE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "device_by_tenant_and_search_text";
 | 
			
		||||
    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;
 | 
			
		||||
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_ADDITIONAL_INFO_PROPERTY;
 | 
			
		||||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_COLUMN_FAMILY_NAME;
 | 
			
		||||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_CUSTOMER_ID_PROPERTY;
 | 
			
		||||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_NAME_PROPERTY;
 | 
			
		||||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_TENANT_ID_PROPERTY;
 | 
			
		||||
import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_TYPE_PROPERTY;
 | 
			
		||||
import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY;
 | 
			
		||||
import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY;
 | 
			
		||||
import static org.thingsboard.server.dao.model.ModelConstants.*;
 | 
			
		||||
 | 
			
		||||
@Table(name = DEVICE_COLUMN_FAMILY_NAME)
 | 
			
		||||
@EqualsAndHashCode
 | 
			
		||||
@ -64,6 +57,9 @@ public final class DeviceEntity implements SearchTextEntity<Device> {
 | 
			
		||||
    @Column(name = DEVICE_NAME_PROPERTY)
 | 
			
		||||
    private String name;
 | 
			
		||||
 | 
			
		||||
    @Column(name = DEVICE_LABEL_PROPERTY)
 | 
			
		||||
    private String label;
 | 
			
		||||
 | 
			
		||||
    @Column(name = SEARCH_TEXT_PROPERTY)
 | 
			
		||||
    private String searchText;
 | 
			
		||||
    
 | 
			
		||||
@ -86,6 +82,7 @@ public final class DeviceEntity implements SearchTextEntity<Device> {
 | 
			
		||||
        }
 | 
			
		||||
        this.name = device.getName();
 | 
			
		||||
        this.type = device.getType();
 | 
			
		||||
        this.label = device.getLabel();
 | 
			
		||||
        this.additionalInfo = device.getAdditionalInfo();
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
@ -163,6 +160,7 @@ public final class DeviceEntity implements SearchTextEntity<Device> {
 | 
			
		||||
        }
 | 
			
		||||
        device.setName(name);
 | 
			
		||||
        device.setType(type);
 | 
			
		||||
        device.setLabel(label);
 | 
			
		||||
        device.setAdditionalInfo(additionalInfo);
 | 
			
		||||
        return device;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -53,6 +53,9 @@ public final class DeviceEntity extends BaseSqlEntity<Device> implements SearchT
 | 
			
		||||
    @Column(name = ModelConstants.DEVICE_NAME_PROPERTY)
 | 
			
		||||
    private String name;
 | 
			
		||||
 | 
			
		||||
    @Column(name = ModelConstants.DEVICE_LABEL_PROPERTY)
 | 
			
		||||
    private String label;
 | 
			
		||||
 | 
			
		||||
    @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
 | 
			
		||||
    private String searchText;
 | 
			
		||||
 | 
			
		||||
@ -76,6 +79,7 @@ public final class DeviceEntity extends BaseSqlEntity<Device> implements SearchT
 | 
			
		||||
        }
 | 
			
		||||
        this.name = device.getName();
 | 
			
		||||
        this.type = device.getType();
 | 
			
		||||
        this.label = device.getLabel();
 | 
			
		||||
        this.additionalInfo = device.getAdditionalInfo();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -101,6 +105,7 @@ public final class DeviceEntity extends BaseSqlEntity<Device> implements SearchT
 | 
			
		||||
        }
 | 
			
		||||
        device.setName(name);
 | 
			
		||||
        device.setType(type);
 | 
			
		||||
        device.setLabel(label);
 | 
			
		||||
        device.setAdditionalInfo(additionalInfo);
 | 
			
		||||
        return device;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -157,6 +157,7 @@ CREATE TABLE IF NOT EXISTS thingsboard.device (
 | 
			
		||||
    customer_id timeuuid,
 | 
			
		||||
    name text,
 | 
			
		||||
    type text,
 | 
			
		||||
    label text,
 | 
			
		||||
    search_text text,
 | 
			
		||||
    additional_info text,
 | 
			
		||||
    PRIMARY KEY (id, tenant_id, customer_id, type)
 | 
			
		||||
 | 
			
		||||
@ -117,6 +117,7 @@ CREATE TABLE IF NOT EXISTS device (
 | 
			
		||||
    customer_id varchar(31),
 | 
			
		||||
    type varchar(255),
 | 
			
		||||
    name varchar(255),
 | 
			
		||||
    label varchar(255),
 | 
			
		||||
    search_text varchar(255),
 | 
			
		||||
    tenant_id varchar(31)
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
@ -347,6 +347,7 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
 | 
			
		||||
        return {
 | 
			
		||||
            origEntity: entity,
 | 
			
		||||
            name: entity.name,
 | 
			
		||||
            label: entity.label?entity.label:"",
 | 
			
		||||
            entityType: entity.id.entityType,
 | 
			
		||||
            id: entity.id.id,
 | 
			
		||||
            entityDescription: entity.additionalInfo?entity.additionalInfo.description:""
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user