Browse Source

Add version to most entities

pull/11112/head
ViacheslavKlimov 2 years ago
parent
commit
67b8ded9f4
  1. 18
      application/src/main/data/upgrade/3.7.0/schema_update.sql
  2. 5
      common/data/src/main/java/org/thingsboard/server/common/data/Customer.java
  3. 8
      common/data/src/main/java/org/thingsboard/server/common/data/DashboardInfo.java
  4. 4
      common/data/src/main/java/org/thingsboard/server/common/data/DeviceProfile.java
  5. 8
      common/data/src/main/java/org/thingsboard/server/common/data/EntityView.java
  6. 9
      common/data/src/main/java/org/thingsboard/server/common/data/User.java
  7. 7
      common/data/src/main/java/org/thingsboard/server/common/data/asset/Asset.java
  8. 5
      common/data/src/main/java/org/thingsboard/server/common/data/asset/AssetProfile.java
  9. 9
      common/data/src/main/java/org/thingsboard/server/common/data/edge/Edge.java
  10. 7
      common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleChain.java
  11. 12
      common/data/src/main/java/org/thingsboard/server/common/data/security/DeviceCredentials.java
  12. 2
      common/data/src/main/java/org/thingsboard/server/common/data/sync/ie/EntityExportData.java
  13. 11
      common/data/src/main/java/org/thingsboard/server/common/data/widget/BaseWidgetType.java
  14. 9
      common/data/src/main/java/org/thingsboard/server/common/data/widget/WidgetTypeDetails.java
  15. 7
      common/data/src/main/java/org/thingsboard/server/common/data/widget/WidgetsBundle.java
  16. 20
      dao/src/main/java/org/thingsboard/server/dao/model/BaseSqlEntity.java
  17. 29
      dao/src/main/java/org/thingsboard/server/dao/model/BaseVersionedSqlEntity.java
  18. 4
      dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractAlarmCommentEntity.java
  19. 15
      dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractAssetEntity.java
  20. 18
      dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractDeviceEntity.java
  21. 16
      dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractEdgeEntity.java
  22. 16
      dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractEntityViewEntity.java
  23. 20
      dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractWidgetTypeEntity.java
  24. 1
      dao/src/main/java/org/thingsboard/server/dao/model/sql/AssetInfoEntity.java
  25. 16
      dao/src/main/java/org/thingsboard/server/dao/model/sql/AssetProfileEntity.java
  26. 9
      dao/src/main/java/org/thingsboard/server/dao/model/sql/CustomerEntity.java
  27. 11
      dao/src/main/java/org/thingsboard/server/dao/model/sql/DashboardEntity.java
  28. 10
      dao/src/main/java/org/thingsboard/server/dao/model/sql/DashboardInfoEntity.java
  29. 21
      dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceCredentialsEntity.java
  30. 11
      dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceProfileEntity.java
  31. 11
      dao/src/main/java/org/thingsboard/server/dao/model/sql/RuleChainEntity.java
  32. 10
      dao/src/main/java/org/thingsboard/server/dao/model/sql/UserEntity.java
  33. 17
      dao/src/main/java/org/thingsboard/server/dao/model/sql/WidgetsBundleEntity.java
  34. 12
      dao/src/main/java/org/thingsboard/server/dao/sql/JpaAbstractDao.java
  35. 16
      dao/src/main/resources/sql/schema-entities.sql

18
application/src/main/data/upgrade/3.7.0/schema_update.sql

@ -14,4 +14,20 @@
-- limitations under the License. -- limitations under the License.
-- --
ALTER TABLE device ADD COLUMN IF NOT EXISTS version INT DEFAULT 0; -- Optimistic locking update START
ALTER TABLE device ADD COLUMN IF NOT EXISTS version INT DEFAULT 1;
ALTER TABLE device_profile ADD COLUMN IF NOT EXISTS version INT DEFAULT 1;
ALTER TABLE device_credentials ADD COLUMN IF NOT EXISTS version INT DEFAULT 1;
ALTER TABLE asset ADD COLUMN IF NOT EXISTS version INT DEFAULT 1;
ALTER TABLE asset_profile ADD COLUMN IF NOT EXISTS version INT DEFAULT 1;
ALTER TABLE entity_view ADD COLUMN IF NOT EXISTS version INT DEFAULT 1;
ALTER TABLE tb_user ADD COLUMN IF NOT EXISTS version INT DEFAULT 1;
ALTER TABLE customer ADD COLUMN IF NOT EXISTS version INT DEFAULT 1;
ALTER TABLE edge ADD COLUMN IF NOT EXISTS version INT DEFAULT 1;
ALTER TABLE rule_chain ADD COLUMN IF NOT EXISTS version INT DEFAULT 1;
ALTER TABLE dashboard ADD COLUMN IF NOT EXISTS version INT DEFAULT 1;
ALTER TABLE widget_type ADD COLUMN IF NOT EXISTS version INT DEFAULT 1;
ALTER TABLE widgets_bundle ADD COLUMN IF NOT EXISTS version INT DEFAULT 1;
-- Optimistic locking update END

5
common/data/src/main/java/org/thingsboard/server/common/data/Customer.java

@ -30,7 +30,7 @@ import org.thingsboard.server.common.data.validation.Length;
import org.thingsboard.server.common.data.validation.NoXss; import org.thingsboard.server.common.data.validation.NoXss;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class Customer extends ContactBased<CustomerId> implements HasTenantId, ExportableEntity<CustomerId>, HasTitle { public class Customer extends ContactBased<CustomerId> implements HasTenantId, ExportableEntity<CustomerId>, HasTitle, HasVersion {
private static final long serialVersionUID = -1599722990298929275L; private static final long serialVersionUID = -1599722990298929275L;
@ -43,6 +43,8 @@ public class Customer extends ContactBased<CustomerId> implements HasTenantId, E
@Getter @Setter @Getter @Setter
private CustomerId externalId; private CustomerId externalId;
@Getter @Setter
private Integer version;
public Customer() { public Customer() {
super(); super();
@ -57,6 +59,7 @@ public class Customer extends ContactBased<CustomerId> implements HasTenantId, E
this.tenantId = customer.getTenantId(); this.tenantId = customer.getTenantId();
this.title = customer.getTitle(); this.title = customer.getTitle();
this.externalId = customer.getExternalId(); this.externalId = customer.getExternalId();
this.version = customer.getVersion();
} }
public TenantId getTenantId() { public TenantId getTenantId() {

8
common/data/src/main/java/org/thingsboard/server/common/data/DashboardInfo.java

@ -17,6 +17,8 @@ package org.thingsboard.server.common.data;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.DashboardId; import org.thingsboard.server.common.data.id.DashboardId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
@ -29,7 +31,7 @@ import java.util.Objects;
import java.util.Set; import java.util.Set;
@Schema @Schema
public class DashboardInfo extends BaseData<DashboardId> implements HasName, HasTenantId, HasTitle, HasImage { public class DashboardInfo extends BaseData<DashboardId> implements HasName, HasTenantId, HasTitle, HasImage, HasVersion {
private static final long serialVersionUID = -9080404114760433799L; private static final long serialVersionUID = -9080404114760433799L;
@ -43,6 +45,9 @@ public class DashboardInfo extends BaseData<DashboardId> implements HasName, Has
private boolean mobileHide; private boolean mobileHide;
private Integer mobileOrder; private Integer mobileOrder;
@Getter @Setter
private Integer version;
public DashboardInfo() { public DashboardInfo() {
super(); super();
} }
@ -59,6 +64,7 @@ public class DashboardInfo extends BaseData<DashboardId> implements HasName, Has
this.assignedCustomers = dashboardInfo.getAssignedCustomers(); this.assignedCustomers = dashboardInfo.getAssignedCustomers();
this.mobileHide = dashboardInfo.isMobileHide(); this.mobileHide = dashboardInfo.isMobileHide();
this.mobileOrder = dashboardInfo.getMobileOrder(); this.mobileOrder = dashboardInfo.getMobileOrder();
this.version = dashboardInfo.getVersion();
} }
@Schema(description = "JSON object with the dashboard Id. " + @Schema(description = "JSON object with the dashboard Id. " +

4
common/data/src/main/java/org/thingsboard/server/common/data/DeviceProfile.java

@ -42,7 +42,7 @@ import java.io.IOException;
@ToString(exclude = {"image", "profileDataBytes"}) @ToString(exclude = {"image", "profileDataBytes"})
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Slf4j @Slf4j
public class DeviceProfile extends BaseData<DeviceProfileId> implements HasName, HasTenantId, HasOtaPackage, HasRuleEngineProfile, ExportableEntity<DeviceProfileId>, HasImage, HasDefaultOption { public class DeviceProfile extends BaseData<DeviceProfileId> implements HasName, HasTenantId, HasOtaPackage, HasRuleEngineProfile, ExportableEntity<DeviceProfileId>, HasImage, HasDefaultOption, HasVersion {
private static final long serialVersionUID = 6998485460273302018L; private static final long serialVersionUID = 6998485460273302018L;
@ -97,6 +97,7 @@ public class DeviceProfile extends BaseData<DeviceProfileId> implements HasName,
private RuleChainId defaultEdgeRuleChainId; private RuleChainId defaultEdgeRuleChainId;
private DeviceProfileId externalId; private DeviceProfileId externalId;
private Integer version;
public DeviceProfile() { public DeviceProfile() {
super(); super();
@ -122,6 +123,7 @@ public class DeviceProfile extends BaseData<DeviceProfileId> implements HasName,
this.softwareId = deviceProfile.getSoftwareId(); this.softwareId = deviceProfile.getSoftwareId();
this.defaultEdgeRuleChainId = deviceProfile.getDefaultEdgeRuleChainId(); this.defaultEdgeRuleChainId = deviceProfile.getDefaultEdgeRuleChainId();
this.externalId = deviceProfile.getExternalId(); this.externalId = deviceProfile.getExternalId();
this.version = deviceProfile.getVersion();
} }
@Schema(description = "JSON object with the device profile Id. " + @Schema(description = "JSON object with the device profile Id. " +

8
common/data/src/main/java/org/thingsboard/server/common/data/EntityView.java

@ -36,7 +36,7 @@ import org.thingsboard.server.common.data.validation.NoXss;
@AllArgsConstructor @AllArgsConstructor
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class EntityView extends BaseDataWithAdditionalInfo<EntityViewId> public class EntityView extends BaseDataWithAdditionalInfo<EntityViewId>
implements HasName, HasTenantId, HasCustomerId, ExportableEntity<EntityViewId> { implements HasName, HasTenantId, HasCustomerId, HasVersion, ExportableEntity<EntityViewId> {
private static final long serialVersionUID = 5582010124562018986L; private static final long serialVersionUID = 5582010124562018986L;
@ -60,6 +60,7 @@ public class EntityView extends BaseDataWithAdditionalInfo<EntityViewId>
private long endTimeMs; private long endTimeMs;
private EntityViewId externalId; private EntityViewId externalId;
private Integer version;
public EntityView() { public EntityView() {
super(); super();
@ -80,6 +81,7 @@ public class EntityView extends BaseDataWithAdditionalInfo<EntityViewId>
this.startTimeMs = entityView.getStartTimeMs(); this.startTimeMs = entityView.getStartTimeMs();
this.endTimeMs = entityView.getEndTimeMs(); this.endTimeMs = entityView.getEndTimeMs();
this.externalId = entityView.getExternalId(); this.externalId = entityView.getExternalId();
this.version = entityView.getVersion();
} }
@Schema(description = "JSON object with Customer Id. Use 'assignEntityViewToCustomer' to change the Customer Id.", accessMode = Schema.AccessMode.READ_ONLY) @Schema(description = "JSON object with Customer Id. Use 'assignEntityViewToCustomer' to change the Customer Id.", accessMode = Schema.AccessMode.READ_ONLY)
@ -102,7 +104,7 @@ public class EntityView extends BaseDataWithAdditionalInfo<EntityViewId>
@Schema(description = "JSON object with the Entity View Id. " + @Schema(description = "JSON object with the Entity View Id. " +
"Specify this field to update the Entity View. " + "Specify this field to update the Entity View. " +
"Referencing non-existing Entity View Id will cause error. " + "Referencing non-existing Entity View Id will cause error. " +
"Omit this field to create new Entity View." ) "Omit this field to create new Entity View.")
@Override @Override
public EntityViewId getId() { public EntityViewId getId() {
return super.getId(); return super.getId();
@ -114,7 +116,7 @@ public class EntityView extends BaseDataWithAdditionalInfo<EntityViewId>
return super.getCreatedTime(); return super.getCreatedTime();
} }
@Schema(description = "Additional parameters of the device",implementation = com.fasterxml.jackson.databind.JsonNode.class) @Schema(description = "Additional parameters of the device", implementation = com.fasterxml.jackson.databind.JsonNode.class)
@Override @Override
public JsonNode getAdditionalInfo() { public JsonNode getAdditionalInfo() {
return super.getAdditionalInfo(); return super.getAdditionalInfo();

9
common/data/src/main/java/org/thingsboard/server/common/data/User.java

@ -20,6 +20,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.EntityId; import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
@ -33,7 +35,7 @@ import static org.apache.commons.lang3.StringUtils.isNotEmpty;
@Schema @Schema
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class User extends BaseDataWithAdditionalInfo<UserId> implements HasName, HasTenantId, HasCustomerId, NotificationRecipient { public class User extends BaseDataWithAdditionalInfo<UserId> implements HasName, HasTenantId, HasCustomerId, NotificationRecipient, HasVersion {
private static final long serialVersionUID = 8250339805336035966L; private static final long serialVersionUID = 8250339805336035966L;
@ -50,6 +52,9 @@ public class User extends BaseDataWithAdditionalInfo<UserId> implements HasName,
@NoXss @NoXss
private String phone; private String phone;
@Getter @Setter
private Integer version;
public User() { public User() {
super(); super();
} }
@ -67,6 +72,7 @@ public class User extends BaseDataWithAdditionalInfo<UserId> implements HasName,
this.firstName = user.getFirstName(); this.firstName = user.getFirstName();
this.lastName = user.getLastName(); this.lastName = user.getLastName();
this.phone = user.getPhone(); this.phone = user.getPhone();
this.version = user.getVersion();
} }
@ -222,4 +228,5 @@ public class User extends BaseDataWithAdditionalInfo<UserId> implements HasName,
public boolean isCustomerUser() { public boolean isCustomerUser() {
return !isSystemAdmin() && !isTenantAdmin(); return !isSystemAdmin() && !isTenantAdmin();
} }
} }

7
common/data/src/main/java/org/thingsboard/server/common/data/asset/Asset.java

@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.ExportableEntity;
import org.thingsboard.server.common.data.HasCustomerId; import org.thingsboard.server.common.data.HasCustomerId;
import org.thingsboard.server.common.data.HasLabel; import org.thingsboard.server.common.data.HasLabel;
import org.thingsboard.server.common.data.HasTenantId; import org.thingsboard.server.common.data.HasTenantId;
import org.thingsboard.server.common.data.HasVersion;
import org.thingsboard.server.common.data.id.AssetId; import org.thingsboard.server.common.data.id.AssetId;
import org.thingsboard.server.common.data.id.AssetProfileId; import org.thingsboard.server.common.data.id.AssetProfileId;
import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.CustomerId;
@ -36,7 +37,7 @@ import java.util.Optional;
@Schema @Schema
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class Asset extends BaseDataWithAdditionalInfo<AssetId> implements HasLabel, HasTenantId, HasCustomerId, ExportableEntity<AssetId> { public class Asset extends BaseDataWithAdditionalInfo<AssetId> implements HasLabel, HasTenantId, HasCustomerId, HasVersion, ExportableEntity<AssetId> {
private static final long serialVersionUID = 2807343040519543363L; private static final long serialVersionUID = 2807343040519543363L;
@ -56,6 +57,8 @@ public class Asset extends BaseDataWithAdditionalInfo<AssetId> implements HasLab
@Getter @Setter @Getter @Setter
private AssetId externalId; private AssetId externalId;
@Getter @Setter
private Integer version;
public Asset() { public Asset() {
super(); super();
@ -74,6 +77,7 @@ public class Asset extends BaseDataWithAdditionalInfo<AssetId> implements HasLab
this.label = asset.getLabel(); this.label = asset.getLabel();
this.assetProfileId = asset.getAssetProfileId(); this.assetProfileId = asset.getAssetProfileId();
this.externalId = asset.getExternalId(); this.externalId = asset.getExternalId();
this.version = asset.getVersion();
} }
public void update(Asset asset) { public void update(Asset asset) {
@ -85,6 +89,7 @@ public class Asset extends BaseDataWithAdditionalInfo<AssetId> implements HasLab
this.assetProfileId = asset.getAssetProfileId(); this.assetProfileId = asset.getAssetProfileId();
Optional.ofNullable(asset.getAdditionalInfo()).ifPresent(this::setAdditionalInfo); Optional.ofNullable(asset.getAdditionalInfo()).ifPresent(this::setAdditionalInfo);
this.externalId = asset.getExternalId(); this.externalId = asset.getExternalId();
this.version = asset.getVersion();
} }
@Schema(description = "JSON object with the asset Id. " + @Schema(description = "JSON object with the asset Id. " +

5
common/data/src/main/java/org/thingsboard/server/common/data/asset/AssetProfile.java

@ -27,6 +27,7 @@ import org.thingsboard.server.common.data.HasImage;
import org.thingsboard.server.common.data.HasName; import org.thingsboard.server.common.data.HasName;
import org.thingsboard.server.common.data.HasRuleEngineProfile; import org.thingsboard.server.common.data.HasRuleEngineProfile;
import org.thingsboard.server.common.data.HasTenantId; import org.thingsboard.server.common.data.HasTenantId;
import org.thingsboard.server.common.data.HasVersion;
import org.thingsboard.server.common.data.id.AssetProfileId; import org.thingsboard.server.common.data.id.AssetProfileId;
import org.thingsboard.server.common.data.id.DashboardId; import org.thingsboard.server.common.data.id.DashboardId;
import org.thingsboard.server.common.data.id.RuleChainId; import org.thingsboard.server.common.data.id.RuleChainId;
@ -39,7 +40,7 @@ import org.thingsboard.server.common.data.validation.NoXss;
@ToString(exclude = {"image"}) @ToString(exclude = {"image"})
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Slf4j @Slf4j
public class AssetProfile extends BaseData<AssetProfileId> implements HasName, HasTenantId, HasRuleEngineProfile, ExportableEntity<AssetProfileId>, HasImage, HasDefaultOption { public class AssetProfile extends BaseData<AssetProfileId> implements HasName, HasTenantId, HasRuleEngineProfile, ExportableEntity<AssetProfileId>, HasImage, HasDefaultOption, HasVersion {
private static final long serialVersionUID = 6998485460273302018L; private static final long serialVersionUID = 6998485460273302018L;
@ -74,6 +75,7 @@ public class AssetProfile extends BaseData<AssetProfileId> implements HasName, H
private RuleChainId defaultEdgeRuleChainId; private RuleChainId defaultEdgeRuleChainId;
private AssetProfileId externalId; private AssetProfileId externalId;
private Integer version;
public AssetProfile() { public AssetProfile() {
super(); super();
@ -95,6 +97,7 @@ public class AssetProfile extends BaseData<AssetProfileId> implements HasName, H
this.defaultQueueName = assetProfile.getDefaultQueueName(); this.defaultQueueName = assetProfile.getDefaultQueueName();
this.defaultEdgeRuleChainId = assetProfile.getDefaultEdgeRuleChainId(); this.defaultEdgeRuleChainId = assetProfile.getDefaultEdgeRuleChainId();
this.externalId = assetProfile.getExternalId(); this.externalId = assetProfile.getExternalId();
this.version = assetProfile.getVersion();
} }
@Schema(description = "JSON object with the asset profile Id. " + @Schema(description = "JSON object with the asset profile Id. " +

9
common/data/src/main/java/org/thingsboard/server/common/data/edge/Edge.java

@ -17,12 +17,14 @@ package org.thingsboard.server.common.data.edge;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import org.thingsboard.server.common.data.BaseDataWithAdditionalInfo; import org.thingsboard.server.common.data.BaseDataWithAdditionalInfo;
import org.thingsboard.server.common.data.HasCustomerId; import org.thingsboard.server.common.data.HasCustomerId;
import org.thingsboard.server.common.data.HasLabel; import org.thingsboard.server.common.data.HasLabel;
import org.thingsboard.server.common.data.HasTenantId; import org.thingsboard.server.common.data.HasTenantId;
import org.thingsboard.server.common.data.HasVersion;
import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.EdgeId; import org.thingsboard.server.common.data.id.EdgeId;
import org.thingsboard.server.common.data.id.RuleChainId; import org.thingsboard.server.common.data.id.RuleChainId;
@ -34,7 +36,7 @@ import org.thingsboard.server.common.data.validation.NoXss;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString @ToString
@Setter @Setter
public class Edge extends BaseDataWithAdditionalInfo<EdgeId> implements HasLabel, HasTenantId, HasCustomerId { public class Edge extends BaseDataWithAdditionalInfo<EdgeId> implements HasLabel, HasTenantId, HasCustomerId, HasVersion {
private static final long serialVersionUID = 4934987555236873728L; private static final long serialVersionUID = 4934987555236873728L;
@ -57,6 +59,9 @@ public class Edge extends BaseDataWithAdditionalInfo<EdgeId> implements HasLabel
@Length(fieldName = "secret") @Length(fieldName = "secret")
private String secret; private String secret;
@Getter
private Integer version;
public Edge() { public Edge() {
super(); super();
} }
@ -75,6 +80,7 @@ public class Edge extends BaseDataWithAdditionalInfo<EdgeId> implements HasLabel
this.name = edge.getName(); this.name = edge.getName();
this.routingKey = edge.getRoutingKey(); this.routingKey = edge.getRoutingKey();
this.secret = edge.getSecret(); this.secret = edge.getSecret();
this.version = edge.getVersion();
} }
public void update(Edge edge) { public void update(Edge edge) {
@ -86,6 +92,7 @@ public class Edge extends BaseDataWithAdditionalInfo<EdgeId> implements HasLabel
this.name = edge.getName(); this.name = edge.getName();
this.routingKey = edge.getRoutingKey(); this.routingKey = edge.getRoutingKey();
this.secret = edge.getSecret(); this.secret = edge.getSecret();
this.version = edge.getVersion();
} }
@Schema(description = "JSON object with the Edge Id. " + @Schema(description = "JSON object with the Edge Id. " +

7
common/data/src/main/java/org/thingsboard/server/common/data/rule/RuleChain.java

@ -26,6 +26,7 @@ import org.thingsboard.server.common.data.ExportableEntity;
import org.thingsboard.server.common.data.HasDefaultOption; import org.thingsboard.server.common.data.HasDefaultOption;
import org.thingsboard.server.common.data.HasName; import org.thingsboard.server.common.data.HasName;
import org.thingsboard.server.common.data.HasTenantId; import org.thingsboard.server.common.data.HasTenantId;
import org.thingsboard.server.common.data.HasVersion;
import org.thingsboard.server.common.data.id.RuleChainId; import org.thingsboard.server.common.data.id.RuleChainId;
import org.thingsboard.server.common.data.id.RuleNodeId; import org.thingsboard.server.common.data.id.RuleNodeId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
@ -36,7 +37,7 @@ import org.thingsboard.server.common.data.validation.NoXss;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Slf4j @Slf4j
public class RuleChain extends BaseDataWithAdditionalInfo<RuleChainId> implements HasName, HasTenantId, ExportableEntity<RuleChainId>, HasDefaultOption { public class RuleChain extends BaseDataWithAdditionalInfo<RuleChainId> implements HasName, HasTenantId, ExportableEntity<RuleChainId>, HasDefaultOption, HasVersion {
private static final long serialVersionUID = -5656679015121935465L; private static final long serialVersionUID = -5656679015121935465L;
@ -58,6 +59,7 @@ public class RuleChain extends BaseDataWithAdditionalInfo<RuleChainId> implement
private transient JsonNode configuration; private transient JsonNode configuration;
private RuleChainId externalId; private RuleChainId externalId;
private Integer version;
@JsonIgnore @JsonIgnore
private byte[] configurationBytes; private byte[] configurationBytes;
@ -79,6 +81,7 @@ public class RuleChain extends BaseDataWithAdditionalInfo<RuleChainId> implement
this.root = ruleChain.isRoot(); this.root = ruleChain.isRoot();
this.setConfiguration(ruleChain.getConfiguration()); this.setConfiguration(ruleChain.getConfiguration());
this.setExternalId(ruleChain.getExternalId()); this.setExternalId(ruleChain.getExternalId());
this.version = ruleChain.getVersion();
} }
@Override @Override
@ -89,7 +92,7 @@ public class RuleChain extends BaseDataWithAdditionalInfo<RuleChainId> implement
@Schema(description = "JSON object with the Rule Chain Id. " + @Schema(description = "JSON object with the Rule Chain Id. " +
"Specify this field to update the Rule Chain. " + "Specify this field to update the Rule Chain. " +
"Referencing non-existing Rule Chain Id will cause error. " + "Referencing non-existing Rule Chain Id will cause error. " +
"Omit this field to create new rule chain." ) "Omit this field to create new rule chain.")
@Override @Override
public RuleChainId getId() { public RuleChainId getId() {
return super.getId(); return super.getId();

12
common/data/src/main/java/org/thingsboard/server/common/data/security/DeviceCredentials.java

@ -17,20 +17,26 @@ package org.thingsboard.server.common.data.security;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.thingsboard.server.common.data.BaseData; import org.thingsboard.server.common.data.BaseData;
import org.thingsboard.server.common.data.HasVersion;
import org.thingsboard.server.common.data.id.DeviceCredentialsId; import org.thingsboard.server.common.data.id.DeviceCredentialsId;
import org.thingsboard.server.common.data.id.DeviceId; import org.thingsboard.server.common.data.id.DeviceId;
@Schema @Schema
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class DeviceCredentials extends BaseData<DeviceCredentialsId> implements DeviceCredentialsFilter { public class DeviceCredentials extends BaseData<DeviceCredentialsId> implements DeviceCredentialsFilter, HasVersion {
private static final long serialVersionUID = -7869261127032877765L; private static final long serialVersionUID = -7869261127032877765L;
private DeviceId deviceId; private DeviceId deviceId;
private DeviceCredentialsType credentialsType; private DeviceCredentialsType credentialsType;
private String credentialsId; private String credentialsId;
private String credentialsValue; private String credentialsValue;
@Getter @Setter
private Integer version;
public DeviceCredentials() { public DeviceCredentials() {
super(); super();
} }
@ -45,6 +51,7 @@ public class DeviceCredentials extends BaseData<DeviceCredentialsId> implements
this.credentialsType = deviceCredentials.getCredentialsType(); this.credentialsType = deviceCredentials.getCredentialsType();
this.credentialsId = deviceCredentials.getCredentialsId(); this.credentialsId = deviceCredentials.getCredentialsId();
this.credentialsValue = deviceCredentials.getCredentialsValue(); this.credentialsValue = deviceCredentials.getCredentialsValue();
this.version = deviceCredentials.getVersion();
} }
@Schema(requiredMode = Schema.RequiredMode.REQUIRED, accessMode = Schema.AccessMode.READ_ONLY, description = "The Id is automatically generated during device creation. " + @Schema(requiredMode = Schema.RequiredMode.REQUIRED, accessMode = Schema.AccessMode.READ_ONLY, description = "The Id is automatically generated during device creation. " +
@ -111,4 +118,5 @@ public class DeviceCredentials extends BaseData<DeviceCredentialsId> implements
+ credentialsId + ", credentialsValue=" + credentialsValue + ", createdTime=" + createdTime + ", id=" + credentialsId + ", credentialsValue=" + credentialsValue + ", createdTime=" + createdTime + ", id="
+ id + "]"; + id + "]";
} }
} }

2
common/data/src/main/java/org/thingsboard/server/common/data/sync/ie/EntityExportData.java

@ -56,7 +56,7 @@ public class EntityExportData<E extends ExportableEntity<? extends EntityId>> {
.comparing(AttributeExportData::getKey).thenComparing(AttributeExportData::getLastUpdateTs); .comparing(AttributeExportData::getKey).thenComparing(AttributeExportData::getLastUpdateTs);
@JsonProperty(index = 2) @JsonProperty(index = 2)
@JsonTbEntity @JsonTbEntity // FIXME: version is serialized. also check single entity export/import from UI!
private E entity; private E entity;
@JsonProperty(index = 1) @JsonProperty(index = 1)
private EntityType entityType; private EntityType entityType;

11
common/data/src/main/java/org/thingsboard/server/common/data/widget/BaseWidgetType.java

@ -17,16 +17,19 @@ package org.thingsboard.server.common.data.widget;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import org.thingsboard.server.common.data.BaseData; import org.thingsboard.server.common.data.BaseData;
import org.thingsboard.server.common.data.HasName; import org.thingsboard.server.common.data.HasName;
import org.thingsboard.server.common.data.HasTenantId; import org.thingsboard.server.common.data.HasTenantId;
import org.thingsboard.server.common.data.HasVersion;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.WidgetTypeId; import org.thingsboard.server.common.data.id.WidgetTypeId;
import org.thingsboard.server.common.data.validation.Length; import org.thingsboard.server.common.data.validation.Length;
import org.thingsboard.server.common.data.validation.NoXss; import org.thingsboard.server.common.data.validation.NoXss;
@Data @Data
public class BaseWidgetType extends BaseData<WidgetTypeId> implements HasName, HasTenantId { @EqualsAndHashCode(callSuper = true)
public class BaseWidgetType extends BaseData<WidgetTypeId> implements HasName, HasTenantId, HasVersion {
private static final long serialVersionUID = 8388684344603660756L; private static final long serialVersionUID = 8388684344603660756L;
@ -44,6 +47,8 @@ public class BaseWidgetType extends BaseData<WidgetTypeId> implements HasName, H
@Schema(description = "Whether widget type is deprecated.", example = "true") @Schema(description = "Whether widget type is deprecated.", example = "true")
private boolean deprecated; private boolean deprecated;
private Integer version;
public BaseWidgetType() { public BaseWidgetType() {
super(); super();
} }
@ -58,12 +63,13 @@ public class BaseWidgetType extends BaseData<WidgetTypeId> implements HasName, H
this.fqn = widgetType.getFqn(); this.fqn = widgetType.getFqn();
this.name = widgetType.getName(); this.name = widgetType.getName();
this.deprecated = widgetType.isDeprecated(); this.deprecated = widgetType.isDeprecated();
this.version = widgetType.getVersion();
} }
@Schema(description = "JSON object with the Widget Type Id. " + @Schema(description = "JSON object with the Widget Type Id. " +
"Specify this field to update the Widget Type. " + "Specify this field to update the Widget Type. " +
"Referencing non-existing Widget Type Id will cause error. " + "Referencing non-existing Widget Type Id will cause error. " +
"Omit this field to create new Widget Type." ) "Omit this field to create new Widget Type.")
@Override @Override
public WidgetTypeId getId() { public WidgetTypeId getId() {
return super.getId(); return super.getId();
@ -74,4 +80,5 @@ public class BaseWidgetType extends BaseData<WidgetTypeId> implements HasName, H
public long getCreatedTime() { public long getCreatedTime() {
return super.getCreatedTime(); return super.getCreatedTime();
} }
} }

9
common/data/src/main/java/org/thingsboard/server/common/data/widget/WidgetTypeDetails.java

@ -18,8 +18,7 @@ package org.thingsboard.server.common.data.widget;
import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.Getter; import lombok.EqualsAndHashCode;
import lombok.Setter;
import org.thingsboard.server.common.data.ExportableEntity; import org.thingsboard.server.common.data.ExportableEntity;
import org.thingsboard.server.common.data.HasImage; import org.thingsboard.server.common.data.HasImage;
import org.thingsboard.server.common.data.HasName; import org.thingsboard.server.common.data.HasName;
@ -29,7 +28,8 @@ import org.thingsboard.server.common.data.validation.Length;
import org.thingsboard.server.common.data.validation.NoXss; import org.thingsboard.server.common.data.validation.NoXss;
@Data @Data
@JsonPropertyOrder({ "fqn", "name", "deprecated", "image", "description", "descriptor", "externalId" }) @EqualsAndHashCode(callSuper = true)
@JsonPropertyOrder({"fqn", "name", "deprecated", "image", "description", "descriptor", "externalId"})
public class WidgetTypeDetails extends WidgetType implements HasName, HasTenantId, HasImage, ExportableEntity<WidgetTypeId> { public class WidgetTypeDetails extends WidgetType implements HasName, HasTenantId, HasImage, ExportableEntity<WidgetTypeId> {
@Schema(description = "Relative or external image URL. Replaced with image data URL (Base64) in case of relative URL and 'inlineImages' option enabled.") @Schema(description = "Relative or external image URL. Replaced with image data URL (Base64) in case of relative URL and 'inlineImages' option enabled.")
@ -42,8 +42,6 @@ public class WidgetTypeDetails extends WidgetType implements HasName, HasTenantI
@Schema(description = "Tags of the widget type") @Schema(description = "Tags of the widget type")
private String[] tags; private String[] tags;
@Getter
@Setter
private WidgetTypeId externalId; private WidgetTypeId externalId;
public WidgetTypeDetails() { public WidgetTypeDetails() {
@ -65,4 +63,5 @@ public class WidgetTypeDetails extends WidgetType implements HasName, HasTenantI
this.tags = widgetTypeDetails.getTags(); this.tags = widgetTypeDetails.getTags();
this.externalId = widgetTypeDetails.getExternalId(); this.externalId = widgetTypeDetails.getExternalId();
} }
} }

7
common/data/src/main/java/org/thingsboard/server/common/data/widget/WidgetsBundle.java

@ -26,6 +26,7 @@ import org.thingsboard.server.common.data.HasImage;
import org.thingsboard.server.common.data.HasName; import org.thingsboard.server.common.data.HasName;
import org.thingsboard.server.common.data.HasTenantId; import org.thingsboard.server.common.data.HasTenantId;
import org.thingsboard.server.common.data.HasTitle; import org.thingsboard.server.common.data.HasTitle;
import org.thingsboard.server.common.data.HasVersion;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.WidgetsBundleId; import org.thingsboard.server.common.data.id.WidgetsBundleId;
import org.thingsboard.server.common.data.validation.Length; import org.thingsboard.server.common.data.validation.Length;
@ -33,7 +34,7 @@ import org.thingsboard.server.common.data.validation.NoXss;
@Schema @Schema
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class WidgetsBundle extends BaseData<WidgetsBundleId> implements HasName, HasTenantId, ExportableEntity<WidgetsBundleId>, HasTitle, HasImage { public class WidgetsBundle extends BaseData<WidgetsBundleId> implements HasName, HasTenantId, ExportableEntity<WidgetsBundleId>, HasTitle, HasImage, HasVersion {
private static final long serialVersionUID = -7627368878362410489L; private static final long serialVersionUID = -7627368878362410489L;
@ -76,6 +77,9 @@ public class WidgetsBundle extends BaseData<WidgetsBundleId> implements HasName,
@Getter @Getter
@Setter @Setter
private WidgetsBundleId externalId; private WidgetsBundleId externalId;
@Getter
@Setter
private Integer version;
public WidgetsBundle() { public WidgetsBundle() {
super(); super();
@ -94,6 +98,7 @@ public class WidgetsBundle extends BaseData<WidgetsBundleId> implements HasName,
this.description = widgetsBundle.getDescription(); this.description = widgetsBundle.getDescription();
this.order = widgetsBundle.getOrder(); this.order = widgetsBundle.getOrder();
this.externalId = widgetsBundle.getExternalId(); this.externalId = widgetsBundle.getExternalId();
this.version = widgetsBundle.getVersion();
} }
@Schema(description = "JSON object with the Widget Bundle Id. " + @Schema(description = "JSON object with the Widget Bundle Id. " +

20
dao/src/main/java/org/thingsboard/server/dao/model/BaseSqlEntity.java

@ -16,17 +16,18 @@
package org.thingsboard.server.dao.model; package org.thingsboard.server.dao.model;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import jakarta.persistence.Column;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.BaseData;
import org.thingsboard.server.common.data.id.EntityId; import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.UUIDBased; import org.thingsboard.server.common.data.id.UUIDBased;
import org.thingsboard.server.dao.DaoUtil; import org.thingsboard.server.dao.DaoUtil;
import jakarta.persistence.Column;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -48,6 +49,19 @@ public abstract class BaseSqlEntity<D> implements BaseEntity<D> {
@Column(name = ModelConstants.CREATED_TIME_PROPERTY, updatable = false) @Column(name = ModelConstants.CREATED_TIME_PROPERTY, updatable = false)
protected long createdTime; protected long createdTime;
public BaseSqlEntity() {
}
public BaseSqlEntity(BaseData<?> domain) {
this.id = domain.getUuidId();
this.createdTime = domain.getCreatedTime();
}
public BaseSqlEntity(BaseSqlEntity<?> entity) {
this.id = entity.id;
this.createdTime = entity.createdTime;
}
@Override @Override
public UUID getUuid() { public UUID getUuid() {
return id; return id;

29
dao/src/main/java/org/thingsboard/server/dao/model/BaseVersionedSqlEntity.java

@ -20,15 +20,42 @@ import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Version; import jakarta.persistence.Version;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.thingsboard.server.common.data.BaseData;
import org.thingsboard.server.common.data.HasVersion; import org.thingsboard.server.common.data.HasVersion;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@MappedSuperclass @MappedSuperclass
public abstract class BaseVersionedSqlEntity<D> extends BaseSqlEntity<D> implements HasVersion { public abstract class BaseVersionedSqlEntity<D extends BaseData & HasVersion> extends BaseSqlEntity<D> implements HasVersion {
@Getter @Setter
@Version @Version
@Column(name = ModelConstants.VERSION_PROPERTY) @Column(name = ModelConstants.VERSION_PROPERTY)
protected Integer version; protected Integer version;
public BaseVersionedSqlEntity() {
super();
}
public BaseVersionedSqlEntity(D domain) {
super(domain);
this.version = domain.getVersion();
}
public BaseVersionedSqlEntity(BaseVersionedSqlEntity<?> entity) {
super(entity);
this.version = entity.version;
}
@Override
public String toString() {
return "BaseVersionedSqlEntity{" +
"id=" + id +
", createdTime=" + createdTime +
", version=" + version +
'}';
}
} }

4
dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractAlarmCommentEntity.java

@ -26,7 +26,6 @@ import org.thingsboard.server.common.data.alarm.AlarmCommentType;
import org.thingsboard.server.common.data.id.AlarmCommentId; import org.thingsboard.server.common.data.id.AlarmCommentId;
import org.thingsboard.server.common.data.id.AlarmId; import org.thingsboard.server.common.data.id.AlarmId;
import org.thingsboard.server.common.data.id.UserId; import org.thingsboard.server.common.data.id.UserId;
import org.thingsboard.server.dao.model.BaseEntity;
import org.thingsboard.server.dao.model.BaseSqlEntity; import org.thingsboard.server.dao.model.BaseSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.util.mapping.JsonConverter; import org.thingsboard.server.dao.util.mapping.JsonConverter;
@ -40,7 +39,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.ALARM_COMMENT_TYPE
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@MappedSuperclass @MappedSuperclass
public abstract class AbstractAlarmCommentEntity<T extends AlarmComment> extends BaseSqlEntity<T> implements BaseEntity<T> { public abstract class AbstractAlarmCommentEntity<T extends AlarmComment> extends BaseSqlEntity<T> {
@Column(name = ALARM_COMMENT_ALARM_ID, columnDefinition = "uuid") @Column(name = ALARM_COMMENT_ALARM_ID, columnDefinition = "uuid")
private UUID alarmId; private UUID alarmId;
@ -94,4 +93,5 @@ public abstract class AbstractAlarmCommentEntity<T extends AlarmComment> extends
alarmComment.setComment(comment); alarmComment.setComment(comment);
return alarmComment; return alarmComment;
} }
} }

15
dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractAssetEntity.java

@ -26,7 +26,7 @@ import org.thingsboard.server.common.data.id.AssetId;
import org.thingsboard.server.common.data.id.AssetProfileId; import org.thingsboard.server.common.data.id.AssetProfileId;
import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.model.BaseSqlEntity; import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.util.mapping.JsonConverter; import org.thingsboard.server.dao.util.mapping.JsonConverter;
@ -42,7 +42,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.EXTERNAL_ID_PROPER
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@MappedSuperclass @MappedSuperclass
public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity<T> { public abstract class AbstractAssetEntity<T extends Asset> extends BaseVersionedSqlEntity<T> {
@Column(name = ASSET_TENANT_ID_PROPERTY) @Column(name = ASSET_TENANT_ID_PROPERTY)
private UUID tenantId; private UUID tenantId;
@ -73,11 +73,8 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity
super(); super();
} }
public AbstractAssetEntity(Asset asset) { public AbstractAssetEntity(T asset) {
if (asset.getId() != null) { super(asset);
this.setUuid(asset.getId().getId());
}
this.setCreatedTime(asset.getCreatedTime());
if (asset.getTenantId() != null) { if (asset.getTenantId() != null) {
this.tenantId = asset.getTenantId().getId(); this.tenantId = asset.getTenantId().getId();
} }
@ -97,8 +94,7 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity
} }
public AbstractAssetEntity(AssetEntity assetEntity) { public AbstractAssetEntity(AssetEntity assetEntity) {
this.setId(assetEntity.getId()); super(assetEntity);
this.setCreatedTime(assetEntity.getCreatedTime());
this.tenantId = assetEntity.getTenantId(); this.tenantId = assetEntity.getTenantId();
this.customerId = assetEntity.getCustomerId(); this.customerId = assetEntity.getCustomerId();
this.assetProfileId = assetEntity.getAssetProfileId(); this.assetProfileId = assetEntity.getAssetProfileId();
@ -112,6 +108,7 @@ public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity
protected Asset toAsset() { protected Asset toAsset() {
Asset asset = new Asset(new AssetId(id)); Asset asset = new Asset(new AssetId(id));
asset.setCreatedTime(createdTime); asset.setCreatedTime(createdTime);
asset.setVersion(version);
if (tenantId != null) { if (tenantId != null) {
asset.setTenantId(TenantId.fromUUID(tenantId)); asset.setTenantId(TenantId.fromUUID(tenantId));
} }

18
dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractDeviceEntity.java

@ -41,7 +41,7 @@ import java.util.UUID;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@MappedSuperclass @MappedSuperclass
public abstract class AbstractDeviceEntity<T extends Device> extends BaseVersionedSqlEntity<T> { public abstract class AbstractDeviceEntity<T extends Device> extends BaseVersionedSqlEntity<T> {
@Column(name = ModelConstants.DEVICE_TENANT_ID_PROPERTY, columnDefinition = "uuid") @Column(name = ModelConstants.DEVICE_TENANT_ID_PROPERTY, columnDefinition = "uuid")
private UUID tenantId; private UUID tenantId;
@ -83,11 +83,8 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseVersion
super(); super();
} }
public AbstractDeviceEntity(Device device) { public AbstractDeviceEntity(T device) {
if (device.getId() != null) { super(device);
this.setUuid(device.getUuidId());
}
this.setCreatedTime(device.getCreatedTime());
if (device.getTenantId() != null) { if (device.getTenantId() != null) {
this.tenantId = device.getTenantId().getId(); this.tenantId = device.getTenantId().getId();
} }
@ -111,12 +108,10 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseVersion
if (device.getExternalId() != null) { if (device.getExternalId() != null) {
this.externalId = device.getExternalId().getId(); this.externalId = device.getExternalId().getId();
} }
this.version = device.getVersion();
} }
public AbstractDeviceEntity(DeviceEntity deviceEntity) { public AbstractDeviceEntity(AbstractDeviceEntity<T> deviceEntity) {
this.setId(deviceEntity.getId()); super(deviceEntity);
this.setCreatedTime(deviceEntity.getCreatedTime());
this.tenantId = deviceEntity.getTenantId(); this.tenantId = deviceEntity.getTenantId();
this.customerId = deviceEntity.getCustomerId(); this.customerId = deviceEntity.getCustomerId();
this.deviceProfileId = deviceEntity.getDeviceProfileId(); this.deviceProfileId = deviceEntity.getDeviceProfileId();
@ -128,12 +123,12 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseVersion
this.firmwareId = deviceEntity.getFirmwareId(); this.firmwareId = deviceEntity.getFirmwareId();
this.softwareId = deviceEntity.getSoftwareId(); this.softwareId = deviceEntity.getSoftwareId();
this.externalId = deviceEntity.getExternalId(); this.externalId = deviceEntity.getExternalId();
this.version = deviceEntity.getVersion();
} }
protected Device toDevice() { protected Device toDevice() {
Device device = new Device(new DeviceId(getUuid())); Device device = new Device(new DeviceId(getUuid()));
device.setCreatedTime(createdTime); device.setCreatedTime(createdTime);
device.setVersion(version);
if (tenantId != null) { if (tenantId != null) {
device.setTenantId(TenantId.fromUUID(tenantId)); device.setTenantId(TenantId.fromUUID(tenantId));
} }
@ -157,7 +152,6 @@ public abstract class AbstractDeviceEntity<T extends Device> extends BaseVersion
if (externalId != null) { if (externalId != null) {
device.setExternalId(new DeviceId(externalId)); device.setExternalId(new DeviceId(externalId));
} }
device.setVersion(version);
return device; return device;
} }

16
dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractEdgeEntity.java

@ -26,7 +26,7 @@ import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.EdgeId; import org.thingsboard.server.common.data.id.EdgeId;
import org.thingsboard.server.common.data.id.RuleChainId; import org.thingsboard.server.common.data.id.RuleChainId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.model.BaseSqlEntity; import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.util.mapping.JsonConverter; import org.thingsboard.server.dao.util.mapping.JsonConverter;
@ -44,7 +44,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.EDGE_TYPE_PROPERTY
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@MappedSuperclass @MappedSuperclass
public abstract class AbstractEdgeEntity<T extends Edge> extends BaseSqlEntity<T> { public abstract class AbstractEdgeEntity<T extends Edge> extends BaseVersionedSqlEntity<T> {
@Column(name = EDGE_TENANT_ID_PROPERTY, columnDefinition = "uuid") @Column(name = EDGE_TENANT_ID_PROPERTY, columnDefinition = "uuid")
private UUID tenantId; private UUID tenantId;
@ -78,11 +78,8 @@ public abstract class AbstractEdgeEntity<T extends Edge> extends BaseSqlEntity<T
super(); super();
} }
public AbstractEdgeEntity(Edge edge) { public AbstractEdgeEntity(T edge) {
if (edge.getId() != null) { super(edge);
this.setUuid(edge.getId().getId());
}
this.setCreatedTime(edge.getCreatedTime());
if (edge.getTenantId() != null) { if (edge.getTenantId() != null) {
this.tenantId = edge.getTenantId().getId(); this.tenantId = edge.getTenantId().getId();
} }
@ -101,8 +98,7 @@ public abstract class AbstractEdgeEntity<T extends Edge> extends BaseSqlEntity<T
} }
public AbstractEdgeEntity(EdgeEntity edgeEntity) { public AbstractEdgeEntity(EdgeEntity edgeEntity) {
this.setId(edgeEntity.getId()); super(edgeEntity);
this.setCreatedTime(edgeEntity.getCreatedTime());
this.tenantId = edgeEntity.getTenantId(); this.tenantId = edgeEntity.getTenantId();
this.customerId = edgeEntity.getCustomerId(); this.customerId = edgeEntity.getCustomerId();
this.rootRuleChainId = edgeEntity.getRootRuleChainId(); this.rootRuleChainId = edgeEntity.getRootRuleChainId();
@ -117,6 +113,7 @@ public abstract class AbstractEdgeEntity<T extends Edge> extends BaseSqlEntity<T
protected Edge toEdge() { protected Edge toEdge() {
Edge edge = new Edge(new EdgeId(getUuid())); Edge edge = new Edge(new EdgeId(getUuid()));
edge.setCreatedTime(createdTime); edge.setCreatedTime(createdTime);
edge.setVersion(version);
if (tenantId != null) { if (tenantId != null) {
edge.setTenantId(TenantId.fromUUID(tenantId)); edge.setTenantId(TenantId.fromUUID(tenantId));
} }
@ -134,4 +131,5 @@ public abstract class AbstractEdgeEntity<T extends Edge> extends BaseSqlEntity<T
edge.setAdditionalInfo(additionalInfo); edge.setAdditionalInfo(additionalInfo);
return edge; return edge;
} }
} }

16
dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractEntityViewEntity.java

@ -32,7 +32,7 @@ import org.thingsboard.server.common.data.id.EntityIdFactory;
import org.thingsboard.server.common.data.id.EntityViewId; import org.thingsboard.server.common.data.id.EntityViewId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.objects.TelemetryEntityView; import org.thingsboard.server.common.data.objects.TelemetryEntityView;
import org.thingsboard.server.dao.model.BaseSqlEntity; import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.util.mapping.JsonConverter; import org.thingsboard.server.dao.util.mapping.JsonConverter;
@ -48,7 +48,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_TYPE_PROPER
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@MappedSuperclass @MappedSuperclass
@Slf4j @Slf4j
public abstract class AbstractEntityViewEntity<T extends EntityView> extends BaseSqlEntity<T> { public abstract class AbstractEntityViewEntity<T extends EntityView> extends BaseVersionedSqlEntity<T> {
@Column(name = ModelConstants.ENTITY_VIEW_ENTITY_ID_PROPERTY) @Column(name = ModelConstants.ENTITY_VIEW_ENTITY_ID_PROPERTY)
private UUID entityId; private UUID entityId;
@ -89,11 +89,8 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas
super(); super();
} }
public AbstractEntityViewEntity(EntityView entityView) { public AbstractEntityViewEntity(T entityView) {
if (entityView.getId() != null) { super(entityView);
this.setUuid(entityView.getId().getId());
}
this.setCreatedTime(entityView.getCreatedTime());
if (entityView.getEntityId() != null) { if (entityView.getEntityId() != null) {
this.entityId = entityView.getEntityId().getId(); this.entityId = entityView.getEntityId().getId();
this.entityType = entityView.getEntityId().getEntityType(); this.entityType = entityView.getEntityId().getEntityType();
@ -120,8 +117,7 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas
} }
public AbstractEntityViewEntity(EntityViewEntity entityViewEntity) { public AbstractEntityViewEntity(EntityViewEntity entityViewEntity) {
this.setId(entityViewEntity.getId()); super(entityViewEntity);
this.setCreatedTime(entityViewEntity.getCreatedTime());
this.entityId = entityViewEntity.getEntityId(); this.entityId = entityViewEntity.getEntityId();
this.entityType = entityViewEntity.getEntityType(); this.entityType = entityViewEntity.getEntityType();
this.tenantId = entityViewEntity.getTenantId(); this.tenantId = entityViewEntity.getTenantId();
@ -138,6 +134,7 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas
protected EntityView toEntityView() { protected EntityView toEntityView() {
EntityView entityView = new EntityView(new EntityViewId(getUuid())); EntityView entityView = new EntityView(new EntityViewId(getUuid()));
entityView.setCreatedTime(createdTime); entityView.setCreatedTime(createdTime);
entityView.setVersion(version);
if (entityId != null) { if (entityId != null) {
entityView.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType.name(), entityId)); entityView.setEntityId(EntityIdFactory.getByTypeAndUuid(entityType.name(), entityId));
@ -163,4 +160,5 @@ public abstract class AbstractEntityViewEntity<T extends EntityView> extends Bas
} }
return entityView; return entityView;
} }
} }

20
dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractWidgetTypeEntity.java

@ -15,23 +15,22 @@
*/ */
package org.thingsboard.server.dao.model.sql; package org.thingsboard.server.dao.model.sql;
import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.WidgetTypeId; import org.thingsboard.server.common.data.id.WidgetTypeId;
import org.thingsboard.server.common.data.widget.BaseWidgetType; import org.thingsboard.server.common.data.widget.BaseWidgetType;
import org.thingsboard.server.dao.model.BaseEntity; import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
import org.thingsboard.server.dao.model.BaseSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import java.util.UUID; import java.util.UUID;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@MappedSuperclass @MappedSuperclass
public abstract class AbstractWidgetTypeEntity<T extends BaseWidgetType> extends BaseSqlEntity<T> { public abstract class AbstractWidgetTypeEntity<T extends BaseWidgetType> extends BaseVersionedSqlEntity<T> {
@Column(name = ModelConstants.WIDGET_TYPE_TENANT_ID_PROPERTY) @Column(name = ModelConstants.WIDGET_TYPE_TENANT_ID_PROPERTY)
private UUID tenantId; private UUID tenantId;
@ -49,11 +48,8 @@ public abstract class AbstractWidgetTypeEntity<T extends BaseWidgetType> extends
super(); super();
} }
public AbstractWidgetTypeEntity(BaseWidgetType widgetType) { public AbstractWidgetTypeEntity(T widgetType) {
if (widgetType.getId() != null) { super(widgetType);
this.setUuid(widgetType.getId().getId());
}
this.setCreatedTime(widgetType.getCreatedTime());
if (widgetType.getTenantId() != null) { if (widgetType.getTenantId() != null) {
this.tenantId = widgetType.getTenantId().getId(); this.tenantId = widgetType.getTenantId().getId();
} }
@ -63,8 +59,7 @@ public abstract class AbstractWidgetTypeEntity<T extends BaseWidgetType> extends
} }
public AbstractWidgetTypeEntity(AbstractWidgetTypeEntity widgetTypeEntity) { public AbstractWidgetTypeEntity(AbstractWidgetTypeEntity widgetTypeEntity) {
this.setId(widgetTypeEntity.getId()); super(widgetTypeEntity);
this.setCreatedTime(widgetTypeEntity.getCreatedTime());
this.tenantId = widgetTypeEntity.getTenantId(); this.tenantId = widgetTypeEntity.getTenantId();
this.fqn = widgetTypeEntity.getFqn(); this.fqn = widgetTypeEntity.getFqn();
this.name = widgetTypeEntity.getName(); this.name = widgetTypeEntity.getName();
@ -74,6 +69,7 @@ public abstract class AbstractWidgetTypeEntity<T extends BaseWidgetType> extends
protected BaseWidgetType toBaseWidgetType() { protected BaseWidgetType toBaseWidgetType() {
BaseWidgetType widgetType = new BaseWidgetType(new WidgetTypeId(getUuid())); BaseWidgetType widgetType = new BaseWidgetType(new WidgetTypeId(getUuid()));
widgetType.setCreatedTime(createdTime); widgetType.setCreatedTime(createdTime);
widgetType.setVersion(version);
if (tenantId != null) { if (tenantId != null) {
widgetType.setTenantId(TenantId.fromUUID(tenantId)); widgetType.setTenantId(TenantId.fromUUID(tenantId));
} }

1
dao/src/main/java/org/thingsboard/server/dao/model/sql/AssetInfoEntity.java

@ -18,6 +18,7 @@ package org.thingsboard.server.dao.model.sql;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.common.data.asset.AssetInfo; import org.thingsboard.server.common.data.asset.AssetInfo;
import java.util.HashMap; import java.util.HashMap;

16
dao/src/main/java/org/thingsboard/server/dao/model/sql/AssetProfileEntity.java

@ -15,6 +15,9 @@
*/ */
package org.thingsboard.server.dao.model.sql; package org.thingsboard.server.dao.model.sql;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.thingsboard.server.common.data.asset.AssetProfile; import org.thingsboard.server.common.data.asset.AssetProfile;
@ -22,19 +25,16 @@ import org.thingsboard.server.common.data.id.AssetProfileId;
import org.thingsboard.server.common.data.id.DashboardId; import org.thingsboard.server.common.data.id.DashboardId;
import org.thingsboard.server.common.data.id.RuleChainId; import org.thingsboard.server.common.data.id.RuleChainId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.model.BaseSqlEntity; import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import java.util.UUID; import java.util.UUID;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Entity @Entity
@Table(name = ModelConstants.ASSET_PROFILE_TABLE_NAME) @Table(name = ModelConstants.ASSET_PROFILE_TABLE_NAME)
public final class AssetProfileEntity extends BaseSqlEntity<AssetProfile> { public final class AssetProfileEntity extends BaseVersionedSqlEntity<AssetProfile> {
@Column(name = ModelConstants.ASSET_PROFILE_TENANT_ID_PROPERTY) @Column(name = ModelConstants.ASSET_PROFILE_TENANT_ID_PROPERTY)
private UUID tenantId; private UUID tenantId;
@ -71,13 +71,10 @@ public final class AssetProfileEntity extends BaseSqlEntity<AssetProfile> {
} }
public AssetProfileEntity(AssetProfile assetProfile) { public AssetProfileEntity(AssetProfile assetProfile) {
if (assetProfile.getId() != null) { super(assetProfile);
this.setUuid(assetProfile.getId().getId());
}
if (assetProfile.getTenantId() != null) { if (assetProfile.getTenantId() != null) {
this.tenantId = assetProfile.getTenantId().getId(); this.tenantId = assetProfile.getTenantId().getId();
} }
this.setCreatedTime(assetProfile.getCreatedTime());
this.name = assetProfile.getName(); this.name = assetProfile.getName();
this.image = assetProfile.getImage(); this.image = assetProfile.getImage();
this.description = assetProfile.getDescription(); this.description = assetProfile.getDescription();
@ -101,6 +98,7 @@ public final class AssetProfileEntity extends BaseSqlEntity<AssetProfile> {
public AssetProfile toData() { public AssetProfile toData() {
AssetProfile assetProfile = new AssetProfile(new AssetProfileId(this.getUuid())); AssetProfile assetProfile = new AssetProfile(new AssetProfileId(this.getUuid()));
assetProfile.setCreatedTime(createdTime); assetProfile.setCreatedTime(createdTime);
assetProfile.setVersion(version);
if (tenantId != null) { if (tenantId != null) {
assetProfile.setTenantId(TenantId.fromUUID(tenantId)); assetProfile.setTenantId(TenantId.fromUUID(tenantId));
} }

9
dao/src/main/java/org/thingsboard/server/dao/model/sql/CustomerEntity.java

@ -26,6 +26,7 @@ import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.model.BaseSqlEntity; import org.thingsboard.server.dao.model.BaseSqlEntity;
import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.util.mapping.JsonConverter; import org.thingsboard.server.dao.util.mapping.JsonConverter;
@ -35,7 +36,7 @@ import java.util.UUID;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Entity @Entity
@Table(name = ModelConstants.CUSTOMER_TABLE_NAME) @Table(name = ModelConstants.CUSTOMER_TABLE_NAME)
public final class CustomerEntity extends BaseSqlEntity<Customer> { public final class CustomerEntity extends BaseVersionedSqlEntity<Customer> {
@Column(name = ModelConstants.CUSTOMER_TENANT_ID_PROPERTY) @Column(name = ModelConstants.CUSTOMER_TENANT_ID_PROPERTY)
private UUID tenantId; private UUID tenantId;
@ -82,10 +83,7 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> {
} }
public CustomerEntity(Customer customer) { public CustomerEntity(Customer customer) {
if (customer.getId() != null) { super(customer);
this.setUuid(customer.getId().getId());
}
this.setCreatedTime(customer.getCreatedTime());
this.tenantId = customer.getTenantId().getId(); this.tenantId = customer.getTenantId().getId();
this.title = customer.getTitle(); this.title = customer.getTitle();
this.country = customer.getCountry(); this.country = customer.getCountry();
@ -107,6 +105,7 @@ public final class CustomerEntity extends BaseSqlEntity<Customer> {
public Customer toData() { public Customer toData() {
Customer customer = new Customer(new CustomerId(this.getUuid())); Customer customer = new Customer(new CustomerId(this.getUuid()));
customer.setCreatedTime(createdTime); customer.setCreatedTime(createdTime);
customer.setVersion(version);
customer.setTenantId(TenantId.fromUUID(tenantId)); customer.setTenantId(TenantId.fromUUID(tenantId));
customer.setTitle(title); customer.setTitle(title);
customer.setCountry(country); customer.setCountry(country);

11
dao/src/main/java/org/thingsboard/server/dao/model/sql/DashboardEntity.java

@ -30,7 +30,7 @@ import org.thingsboard.server.common.data.ShortCustomerInfo;
import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.id.DashboardId; import org.thingsboard.server.common.data.id.DashboardId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.model.BaseSqlEntity; import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.util.mapping.JsonConverter; import org.thingsboard.server.dao.util.mapping.JsonConverter;
@ -42,7 +42,7 @@ import java.util.UUID;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Entity @Entity
@Table(name = ModelConstants.DASHBOARD_TABLE_NAME) @Table(name = ModelConstants.DASHBOARD_TABLE_NAME)
public final class DashboardEntity extends BaseSqlEntity<Dashboard> { public final class DashboardEntity extends BaseVersionedSqlEntity<Dashboard> {
private static final JavaType assignedCustomersType = private static final JavaType assignedCustomersType =
JacksonUtil.constructCollectionType(HashSet.class, ShortCustomerInfo.class); JacksonUtil.constructCollectionType(HashSet.class, ShortCustomerInfo.class);
@ -77,10 +77,7 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> {
} }
public DashboardEntity(Dashboard dashboard) { public DashboardEntity(Dashboard dashboard) {
if (dashboard.getId() != null) { super(dashboard);
this.setUuid(dashboard.getId().getId());
}
this.setCreatedTime(dashboard.getCreatedTime());
if (dashboard.getTenantId() != null) { if (dashboard.getTenantId() != null) {
this.tenantId = dashboard.getTenantId().getId(); this.tenantId = dashboard.getTenantId().getId();
} }
@ -105,6 +102,7 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> {
public Dashboard toData() { public Dashboard toData() {
Dashboard dashboard = new Dashboard(new DashboardId(this.getUuid())); Dashboard dashboard = new Dashboard(new DashboardId(this.getUuid()));
dashboard.setCreatedTime(this.getCreatedTime()); dashboard.setCreatedTime(this.getCreatedTime());
dashboard.setVersion(version);
if (tenantId != null) { if (tenantId != null) {
dashboard.setTenantId(TenantId.fromUUID(tenantId)); dashboard.setTenantId(TenantId.fromUUID(tenantId));
} }
@ -125,4 +123,5 @@ public final class DashboardEntity extends BaseSqlEntity<Dashboard> {
} }
return dashboard; return dashboard;
} }
} }

10
dao/src/main/java/org/thingsboard/server/dao/model/sql/DashboardInfoEntity.java

@ -28,7 +28,7 @@ import org.thingsboard.server.common.data.ShortCustomerInfo;
import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.id.DashboardId; import org.thingsboard.server.common.data.id.DashboardId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.model.BaseSqlEntity; import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import java.util.HashSet; import java.util.HashSet;
@ -39,7 +39,7 @@ import java.util.UUID;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Entity @Entity
@Table(name = ModelConstants.DASHBOARD_TABLE_NAME) @Table(name = ModelConstants.DASHBOARD_TABLE_NAME)
public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> { public class DashboardInfoEntity extends BaseVersionedSqlEntity<DashboardInfo> {
private static final JavaType assignedCustomersType = private static final JavaType assignedCustomersType =
JacksonUtil.constructCollectionType(HashSet.class, ShortCustomerInfo.class); JacksonUtil.constructCollectionType(HashSet.class, ShortCustomerInfo.class);
@ -67,10 +67,7 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> {
} }
public DashboardInfoEntity(DashboardInfo dashboardInfo) { public DashboardInfoEntity(DashboardInfo dashboardInfo) {
if (dashboardInfo.getId() != null) { super(dashboardInfo);
this.setUuid(dashboardInfo.getId().getId());
}
this.setCreatedTime(dashboardInfo.getCreatedTime());
if (dashboardInfo.getTenantId() != null) { if (dashboardInfo.getTenantId() != null) {
this.tenantId = dashboardInfo.getTenantId().getId(); this.tenantId = dashboardInfo.getTenantId().getId();
} }
@ -91,6 +88,7 @@ public class DashboardInfoEntity extends BaseSqlEntity<DashboardInfo> {
public DashboardInfo toData() { public DashboardInfo toData() {
DashboardInfo dashboardInfo = new DashboardInfo(new DashboardId(this.getUuid())); DashboardInfo dashboardInfo = new DashboardInfo(new DashboardId(this.getUuid()));
dashboardInfo.setCreatedTime(createdTime); dashboardInfo.setCreatedTime(createdTime);
dashboardInfo.setVersion(version);
if (tenantId != null) { if (tenantId != null) {
dashboardInfo.setTenantId(TenantId.fromUUID(tenantId)); dashboardInfo.setTenantId(TenantId.fromUUID(tenantId));
} }

21
dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceCredentialsEntity.java

@ -15,28 +15,27 @@
*/ */
package org.thingsboard.server.dao.model.sql; package org.thingsboard.server.dao.model.sql;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Table;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.thingsboard.server.common.data.id.DeviceCredentialsId; import org.thingsboard.server.common.data.id.DeviceCredentialsId;
import org.thingsboard.server.common.data.id.DeviceId; import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.security.DeviceCredentials; import org.thingsboard.server.common.data.security.DeviceCredentials;
import org.thingsboard.server.common.data.security.DeviceCredentialsType; import org.thingsboard.server.common.data.security.DeviceCredentialsType;
import org.thingsboard.server.dao.model.BaseEntity; import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
import org.thingsboard.server.dao.model.BaseSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Table;
import java.util.UUID; import java.util.UUID;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Entity @Entity
@Table(name = ModelConstants.DEVICE_CREDENTIALS_TABLE_NAME) @Table(name = ModelConstants.DEVICE_CREDENTIALS_TABLE_NAME)
public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentials> implements BaseEntity<DeviceCredentials> { public final class DeviceCredentialsEntity extends BaseVersionedSqlEntity<DeviceCredentials> {
@Column(name = ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY) @Column(name = ModelConstants.DEVICE_CREDENTIALS_DEVICE_ID_PROPERTY)
private UUID deviceId; private UUID deviceId;
@ -56,10 +55,7 @@ public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentia
} }
public DeviceCredentialsEntity(DeviceCredentials deviceCredentials) { public DeviceCredentialsEntity(DeviceCredentials deviceCredentials) {
if (deviceCredentials.getId() != null) { super(deviceCredentials);
this.setUuid(deviceCredentials.getId().getId());
}
this.setCreatedTime(deviceCredentials.getCreatedTime());
if (deviceCredentials.getDeviceId() != null) { if (deviceCredentials.getDeviceId() != null) {
this.deviceId = deviceCredentials.getDeviceId().getId(); this.deviceId = deviceCredentials.getDeviceId().getId();
} }
@ -72,6 +68,7 @@ public final class DeviceCredentialsEntity extends BaseSqlEntity<DeviceCredentia
public DeviceCredentials toData() { public DeviceCredentials toData() {
DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(this.getUuid())); DeviceCredentials deviceCredentials = new DeviceCredentials(new DeviceCredentialsId(this.getUuid()));
deviceCredentials.setCreatedTime(createdTime); deviceCredentials.setCreatedTime(createdTime);
deviceCredentials.setVersion(version);
if (deviceId != null) { if (deviceId != null) {
deviceCredentials.setDeviceId(new DeviceId(deviceId)); deviceCredentials.setDeviceId(new DeviceId(deviceId));
} }

11
dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceProfileEntity.java

@ -38,7 +38,7 @@ import org.thingsboard.server.common.data.id.DeviceProfileId;
import org.thingsboard.server.common.data.id.OtaPackageId; import org.thingsboard.server.common.data.id.OtaPackageId;
import org.thingsboard.server.common.data.id.RuleChainId; import org.thingsboard.server.common.data.id.RuleChainId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.dao.model.BaseSqlEntity; import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.util.mapping.JsonConverter; import org.thingsboard.server.dao.util.mapping.JsonConverter;
@ -48,7 +48,7 @@ import java.util.UUID;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Entity @Entity
@Table(name = ModelConstants.DEVICE_PROFILE_TABLE_NAME) @Table(name = ModelConstants.DEVICE_PROFILE_TABLE_NAME)
public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> { public final class DeviceProfileEntity extends BaseVersionedSqlEntity<DeviceProfile> {
@Column(name = ModelConstants.DEVICE_PROFILE_TENANT_ID_PROPERTY) @Column(name = ModelConstants.DEVICE_PROFILE_TENANT_ID_PROPERTY)
private UUID tenantId; private UUID tenantId;
@ -111,13 +111,10 @@ public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> {
} }
public DeviceProfileEntity(DeviceProfile deviceProfile) { public DeviceProfileEntity(DeviceProfile deviceProfile) {
if (deviceProfile.getId() != null) { super(deviceProfile);
this.setUuid(deviceProfile.getId().getId());
}
if (deviceProfile.getTenantId() != null) { if (deviceProfile.getTenantId() != null) {
this.tenantId = deviceProfile.getTenantId().getId(); this.tenantId = deviceProfile.getTenantId().getId();
} }
this.setCreatedTime(deviceProfile.getCreatedTime());
this.name = deviceProfile.getName(); this.name = deviceProfile.getName();
this.type = deviceProfile.getType(); this.type = deviceProfile.getType();
this.image = deviceProfile.getImage(); this.image = deviceProfile.getImage();
@ -152,6 +149,7 @@ public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> {
public DeviceProfile toData() { public DeviceProfile toData() {
DeviceProfile deviceProfile = new DeviceProfile(new DeviceProfileId(this.getUuid())); DeviceProfile deviceProfile = new DeviceProfile(new DeviceProfileId(this.getUuid()));
deviceProfile.setCreatedTime(createdTime); deviceProfile.setCreatedTime(createdTime);
deviceProfile.setVersion(version);
if (tenantId != null) { if (tenantId != null) {
deviceProfile.setTenantId(TenantId.fromUUID(tenantId)); deviceProfile.setTenantId(TenantId.fromUUID(tenantId));
} }
@ -187,4 +185,5 @@ public final class DeviceProfileEntity extends BaseSqlEntity<DeviceProfile> {
return deviceProfile; return deviceProfile;
} }
} }

11
dao/src/main/java/org/thingsboard/server/dao/model/sql/RuleChainEntity.java

@ -30,7 +30,7 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.rule.RuleChain; import org.thingsboard.server.common.data.rule.RuleChain;
import org.thingsboard.server.common.data.rule.RuleChainType; import org.thingsboard.server.common.data.rule.RuleChainType;
import org.thingsboard.server.dao.DaoUtil; import org.thingsboard.server.dao.DaoUtil;
import org.thingsboard.server.dao.model.BaseSqlEntity; import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.util.mapping.JsonConverter; import org.thingsboard.server.dao.util.mapping.JsonConverter;
@ -40,7 +40,7 @@ import java.util.UUID;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Entity @Entity
@Table(name = ModelConstants.RULE_CHAIN_TABLE_NAME) @Table(name = ModelConstants.RULE_CHAIN_TABLE_NAME)
public class RuleChainEntity extends BaseSqlEntity<RuleChain> { public class RuleChainEntity extends BaseVersionedSqlEntity<RuleChain> {
@Column(name = ModelConstants.RULE_CHAIN_TENANT_ID_PROPERTY) @Column(name = ModelConstants.RULE_CHAIN_TENANT_ID_PROPERTY)
private UUID tenantId; private UUID tenantId;
@ -76,10 +76,7 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> {
} }
public RuleChainEntity(RuleChain ruleChain) { public RuleChainEntity(RuleChain ruleChain) {
if (ruleChain.getId() != null) { super(ruleChain);
this.setUuid(ruleChain.getUuidId());
}
this.setCreatedTime(ruleChain.getCreatedTime());
this.tenantId = DaoUtil.getId(ruleChain.getTenantId()); this.tenantId = DaoUtil.getId(ruleChain.getTenantId());
this.name = ruleChain.getName(); this.name = ruleChain.getName();
this.type = ruleChain.getType(); this.type = ruleChain.getType();
@ -99,6 +96,7 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> {
public RuleChain toData() { public RuleChain toData() {
RuleChain ruleChain = new RuleChain(new RuleChainId(this.getUuid())); RuleChain ruleChain = new RuleChain(new RuleChainId(this.getUuid()));
ruleChain.setCreatedTime(createdTime); ruleChain.setCreatedTime(createdTime);
ruleChain.setVersion(version);
ruleChain.setTenantId(TenantId.fromUUID(tenantId)); ruleChain.setTenantId(TenantId.fromUUID(tenantId));
ruleChain.setName(name); ruleChain.setName(name);
ruleChain.setType(type); ruleChain.setType(type);
@ -114,4 +112,5 @@ public class RuleChainEntity extends BaseSqlEntity<RuleChain> {
} }
return ruleChain; return ruleChain;
} }
} }

10
dao/src/main/java/org/thingsboard/server/dao/model/sql/UserEntity.java

@ -29,7 +29,7 @@ import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.UserId; import org.thingsboard.server.common.data.id.UserId;
import org.thingsboard.server.common.data.security.Authority; import org.thingsboard.server.common.data.security.Authority;
import org.thingsboard.server.dao.model.BaseSqlEntity; import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.util.mapping.JsonConverter; import org.thingsboard.server.dao.util.mapping.JsonConverter;
@ -42,7 +42,7 @@ import java.util.UUID;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Entity @Entity
@Table(name = ModelConstants.USER_PG_HIBERNATE_TABLE_NAME) @Table(name = ModelConstants.USER_PG_HIBERNATE_TABLE_NAME)
public class UserEntity extends BaseSqlEntity<User> { public class UserEntity extends BaseVersionedSqlEntity<User> {
@Column(name = ModelConstants.USER_TENANT_ID_PROPERTY) @Column(name = ModelConstants.USER_TENANT_ID_PROPERTY)
private UUID tenantId; private UUID tenantId;
@ -74,10 +74,7 @@ public class UserEntity extends BaseSqlEntity<User> {
} }
public UserEntity(User user) { public UserEntity(User user) {
if (user.getId() != null) { super(user);
this.setUuid(user.getId().getId());
}
this.setCreatedTime(user.getCreatedTime());
this.authority = user.getAuthority(); this.authority = user.getAuthority();
if (user.getTenantId() != null) { if (user.getTenantId() != null) {
this.tenantId = user.getTenantId().getId(); this.tenantId = user.getTenantId().getId();
@ -96,6 +93,7 @@ public class UserEntity extends BaseSqlEntity<User> {
public User toData() { public User toData() {
User user = new User(new UserId(this.getUuid())); User user = new User(new UserId(this.getUuid()));
user.setCreatedTime(createdTime); user.setCreatedTime(createdTime);
user.setVersion(version);
user.setAuthority(authority); user.setAuthority(authority);
if (tenantId != null) { if (tenantId != null) {
user.setTenantId(TenantId.fromUUID(tenantId)); user.setTenantId(TenantId.fromUUID(tenantId));

17
dao/src/main/java/org/thingsboard/server/dao/model/sql/WidgetsBundleEntity.java

@ -16,24 +16,24 @@
package org.thingsboard.server.dao.model.sql; package org.thingsboard.server.dao.model.sql;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.WidgetsBundleId; import org.thingsboard.server.common.data.id.WidgetsBundleId;
import org.thingsboard.server.common.data.widget.WidgetsBundle; import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.dao.model.BaseSqlEntity; import org.thingsboard.server.dao.model.BaseVersionedSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import java.util.UUID; import java.util.UUID;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Entity @Entity
@Table(name = ModelConstants.WIDGETS_BUNDLE_TABLE_NAME) @Table(name = ModelConstants.WIDGETS_BUNDLE_TABLE_NAME)
public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> { public final class WidgetsBundleEntity extends BaseVersionedSqlEntity<WidgetsBundle> {
@Column(name = ModelConstants.WIDGETS_BUNDLE_TENANT_ID_PROPERTY) @Column(name = ModelConstants.WIDGETS_BUNDLE_TENANT_ID_PROPERTY)
private UUID tenantId; private UUID tenantId;
@ -61,10 +61,7 @@ public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> {
} }
public WidgetsBundleEntity(WidgetsBundle widgetsBundle) { public WidgetsBundleEntity(WidgetsBundle widgetsBundle) {
if (widgetsBundle.getId() != null) { super(widgetsBundle);
this.setUuid(widgetsBundle.getId().getId());
}
this.setCreatedTime(widgetsBundle.getCreatedTime());
if (widgetsBundle.getTenantId() != null) { if (widgetsBundle.getTenantId() != null) {
this.tenantId = widgetsBundle.getTenantId().getId(); this.tenantId = widgetsBundle.getTenantId().getId();
} }
@ -82,6 +79,7 @@ public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> {
public WidgetsBundle toData() { public WidgetsBundle toData() {
WidgetsBundle widgetsBundle = new WidgetsBundle(new WidgetsBundleId(id)); WidgetsBundle widgetsBundle = new WidgetsBundle(new WidgetsBundleId(id));
widgetsBundle.setCreatedTime(createdTime); widgetsBundle.setCreatedTime(createdTime);
widgetsBundle.setVersion(version);
if (tenantId != null) { if (tenantId != null) {
widgetsBundle.setTenantId(TenantId.fromUUID(tenantId)); widgetsBundle.setTenantId(TenantId.fromUUID(tenantId));
} }
@ -95,4 +93,5 @@ public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> {
} }
return widgetsBundle; return widgetsBundle;
} }
} }

12
dao/src/main/java/org/thingsboard/server/dao/sql/JpaAbstractDao.java

@ -85,12 +85,18 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D>
protected E doSave(E entity, boolean isNew) { protected E doSave(E entity, boolean isNew) {
if (isNew) { if (isNew) {
if (entity instanceof HasVersion versionedEntity) {
versionedEntity.setVersion(1);
}
entityManager.persist(entity); entityManager.persist(entity);
} else { } else {
if (entity instanceof HasVersion versionedEntity) { if (entity instanceof HasVersion versionedEntity) {
if (versionedEntity.getVersion() == null) { if (versionedEntity.getVersion() == null) {
HasVersion existingEntity = entityManager.find(versionedEntity.getClass(), entity.getUuid()); // fixme tmp
versionedEntity.setVersion(existingEntity.getVersion()); // manually resetting the version to latest to allow force overwrite of the entity throw new IllegalArgumentException("TEST - unexpected null version for " + versionedEntity);
// HasVersion existingEntity = entityManager.find(versionedEntity.getClass(), entity.getUuid());
// versionedEntity.setVersion(existingEntity.getVersion()); // manually resetting the version to latest to allow force overwrite of the entity
} }
entity = entityManager.merge(entity); entity = entityManager.merge(entity);
entityManager.flush(); entityManager.flush();
@ -137,6 +143,8 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D>
@Override @Override
@Transactional @Transactional
public boolean removeById(TenantId tenantId, UUID id) { public boolean removeById(TenantId tenantId, UUID id) {
// jdbcTemplate.queryForObject("DELETE FROM " + getEntityType().getTableName() + " WHERE id = ? RETURNING version", Integer.class, id);
// TODO: increment version...
getRepository().deleteById(id); getRepository().deleteById(id);
log.debug("Remove request: {}", id); log.debug("Remove request: {}", id);
return !getRepository().existsById(id); return !getRepository().existsById(id);

16
dao/src/main/resources/sql/schema-entities.sql

@ -145,6 +145,7 @@ CREATE TABLE IF NOT EXISTS customer (
zip varchar(255), zip varchar(255),
external_id uuid, external_id uuid,
is_public boolean, is_public boolean,
version INT DEFAULT 1,
CONSTRAINT customer_title_unq_key UNIQUE (tenant_id, title), CONSTRAINT customer_title_unq_key UNIQUE (tenant_id, title),
CONSTRAINT customer_external_id_unq_key UNIQUE (tenant_id, external_id) CONSTRAINT customer_external_id_unq_key UNIQUE (tenant_id, external_id)
); );
@ -160,6 +161,7 @@ CREATE TABLE IF NOT EXISTS dashboard (
mobile_order int, mobile_order int,
image varchar(1000000), image varchar(1000000),
external_id uuid, external_id uuid,
version INT DEFAULT 1,
CONSTRAINT dashboard_external_id_unq_key UNIQUE (tenant_id, external_id) CONSTRAINT dashboard_external_id_unq_key UNIQUE (tenant_id, external_id)
); );
@ -175,6 +177,7 @@ CREATE TABLE IF NOT EXISTS rule_chain (
debug_mode boolean, debug_mode boolean,
tenant_id uuid, tenant_id uuid,
external_id uuid, external_id uuid,
version INT DEFAULT 1,
CONSTRAINT rule_chain_external_id_unq_key UNIQUE (tenant_id, external_id) CONSTRAINT rule_chain_external_id_unq_key UNIQUE (tenant_id, external_id)
); );
@ -252,6 +255,7 @@ CREATE TABLE IF NOT EXISTS asset_profile (
default_queue_name varchar(255), default_queue_name varchar(255),
default_edge_rule_chain_id uuid, default_edge_rule_chain_id uuid,
external_id uuid, external_id uuid,
version INT DEFAULT 1,
CONSTRAINT asset_profile_name_unq_key UNIQUE (tenant_id, name), CONSTRAINT asset_profile_name_unq_key UNIQUE (tenant_id, name),
CONSTRAINT asset_profile_external_id_unq_key UNIQUE (tenant_id, external_id), CONSTRAINT asset_profile_external_id_unq_key UNIQUE (tenant_id, external_id),
CONSTRAINT fk_default_rule_chain_asset_profile FOREIGN KEY (default_rule_chain_id) REFERENCES rule_chain(id), CONSTRAINT fk_default_rule_chain_asset_profile FOREIGN KEY (default_rule_chain_id) REFERENCES rule_chain(id),
@ -270,6 +274,7 @@ CREATE TABLE IF NOT EXISTS asset (
tenant_id uuid, tenant_id uuid,
type varchar(255), type varchar(255),
external_id uuid, external_id uuid,
version INT DEFAULT 1,
CONSTRAINT asset_name_unq_key UNIQUE (tenant_id, name), CONSTRAINT asset_name_unq_key UNIQUE (tenant_id, name),
CONSTRAINT asset_external_id_unq_key UNIQUE (tenant_id, external_id), CONSTRAINT asset_external_id_unq_key UNIQUE (tenant_id, external_id),
CONSTRAINT fk_asset_profile FOREIGN KEY (asset_profile_id) REFERENCES asset_profile(id) CONSTRAINT fk_asset_profile FOREIGN KEY (asset_profile_id) REFERENCES asset_profile(id)
@ -295,6 +300,7 @@ CREATE TABLE IF NOT EXISTS device_profile (
provision_device_key varchar, provision_device_key varchar,
default_edge_rule_chain_id uuid, default_edge_rule_chain_id uuid,
external_id uuid, external_id uuid,
version INT DEFAULT 1,
CONSTRAINT device_profile_name_unq_key UNIQUE (tenant_id, name), CONSTRAINT device_profile_name_unq_key UNIQUE (tenant_id, name),
CONSTRAINT device_provision_key_unq_key UNIQUE (provision_device_key), CONSTRAINT device_provision_key_unq_key UNIQUE (provision_device_key),
CONSTRAINT device_profile_external_id_unq_key UNIQUE (tenant_id, external_id), CONSTRAINT device_profile_external_id_unq_key UNIQUE (tenant_id, external_id),
@ -340,7 +346,7 @@ CREATE TABLE IF NOT EXISTS device (
firmware_id uuid, firmware_id uuid,
software_id uuid, software_id uuid,
external_id uuid, external_id uuid,
version INT DEFAULT 0, version INT DEFAULT 1,
CONSTRAINT device_name_unq_key UNIQUE (tenant_id, name), CONSTRAINT device_name_unq_key UNIQUE (tenant_id, name),
CONSTRAINT device_external_id_unq_key UNIQUE (tenant_id, external_id), CONSTRAINT device_external_id_unq_key UNIQUE (tenant_id, external_id),
CONSTRAINT fk_device_profile FOREIGN KEY (device_profile_id) REFERENCES device_profile(id), CONSTRAINT fk_device_profile FOREIGN KEY (device_profile_id) REFERENCES device_profile(id),
@ -355,6 +361,7 @@ CREATE TABLE IF NOT EXISTS device_credentials (
credentials_type varchar(255), credentials_type varchar(255),
credentials_value varchar, credentials_value varchar,
device_id uuid, device_id uuid,
version INT DEFAULT 1,
CONSTRAINT device_credentials_id_unq_key UNIQUE (credentials_id), CONSTRAINT device_credentials_id_unq_key UNIQUE (credentials_id),
CONSTRAINT device_credentials_device_id_unq_key UNIQUE (device_id) CONSTRAINT device_credentials_device_id_unq_key UNIQUE (device_id)
); );
@ -439,7 +446,8 @@ CREATE TABLE IF NOT EXISTS tb_user (
first_name varchar(255), first_name varchar(255),
last_name varchar(255), last_name varchar(255),
phone varchar(255), phone varchar(255),
tenant_id uuid tenant_id uuid,
version INT DEFAULT 1
); );
CREATE TABLE IF NOT EXISTS tenant_profile ( CREATE TABLE IF NOT EXISTS tenant_profile (
@ -495,6 +503,7 @@ CREATE TABLE IF NOT EXISTS widget_type (
description varchar(1024), description varchar(1024),
tags text[], tags text[],
external_id uuid, external_id uuid,
version INT DEFAULT 1,
CONSTRAINT uq_widget_type_fqn UNIQUE (tenant_id, fqn), CONSTRAINT uq_widget_type_fqn UNIQUE (tenant_id, fqn),
CONSTRAINT widget_type_external_id_unq_key UNIQUE (tenant_id, external_id) CONSTRAINT widget_type_external_id_unq_key UNIQUE (tenant_id, external_id)
); );
@ -509,6 +518,7 @@ CREATE TABLE IF NOT EXISTS widgets_bundle (
description varchar(1024), description varchar(1024),
widgets_bundle_order int, widgets_bundle_order int,
external_id uuid, external_id uuid,
version INT DEFAULT 1,
CONSTRAINT uq_widgets_bundle_alias UNIQUE (tenant_id, alias), CONSTRAINT uq_widgets_bundle_alias UNIQUE (tenant_id, alias),
CONSTRAINT widgets_bundle_external_id_unq_key UNIQUE (tenant_id, external_id) CONSTRAINT widgets_bundle_external_id_unq_key UNIQUE (tenant_id, external_id)
); );
@ -536,6 +546,7 @@ CREATE TABLE IF NOT EXISTS entity_view (
end_ts bigint, end_ts bigint,
additional_info varchar, additional_info varchar,
external_id uuid, external_id uuid,
version INT DEFAULT 1,
CONSTRAINT entity_view_external_id_unq_key UNIQUE (tenant_id, external_id) CONSTRAINT entity_view_external_id_unq_key UNIQUE (tenant_id, external_id)
); );
@ -741,6 +752,7 @@ CREATE TABLE IF NOT EXISTS edge (
routing_key varchar(255), routing_key varchar(255),
secret varchar(255), secret varchar(255),
tenant_id uuid, tenant_id uuid,
version INT DEFAULT 1,
CONSTRAINT edge_name_unq_key UNIQUE (tenant_id, name), CONSTRAINT edge_name_unq_key UNIQUE (tenant_id, name),
CONSTRAINT edge_routing_key_unq_key UNIQUE (routing_key) CONSTRAINT edge_routing_key_unq_key UNIQUE (routing_key)
); );

Loading…
Cancel
Save