Browse Source
AI rule node: make name of the AI settings unique within the scope of the tenant
pull/13371/head
Dmytro Skarzhynets
1 year ago
No known key found for this signature in database
GPG Key ID: 2B51652F224037DF
4 changed files with
12 additions and
4 deletions
-
application/src/main/data/upgrade/basic/schema_update.sql
-
common/data/src/main/java/org/thingsboard/server/common/data/ai/AiSettings.java
-
dao/src/main/java/org/thingsboard/server/dao/ai/AiSettingsServiceImpl.java
-
dao/src/main/resources/sql/schema-entities.sql
|
|
|
@ -22,5 +22,6 @@ CREATE TABLE ai_settings ( |
|
|
|
name VARCHAR(255) NOT NULL, |
|
|
|
provider VARCHAR(255) NOT NULL, |
|
|
|
model VARCHAR(255) NOT NULL, |
|
|
|
api_key VARCHAR(1000) NOT NULL |
|
|
|
api_key VARCHAR(1000) NOT NULL, |
|
|
|
CONSTRAINT ai_settings_name_unq_key UNIQUE (tenant_id, name) |
|
|
|
); |
|
|
|
|
|
|
|
@ -58,7 +58,7 @@ public final class AiSettings extends BaseData<AiSettingsId> implements HasTenan |
|
|
|
@Schema( |
|
|
|
requiredMode = Schema.RequiredMode.REQUIRED, |
|
|
|
accessMode = Schema.AccessMode.READ_WRITE, |
|
|
|
description = "Human-readable name of the AI settings", |
|
|
|
description = "Human-readable name of the AI settings; must be unique within the scope of the tenant", |
|
|
|
example = "Default AI Settings" |
|
|
|
) |
|
|
|
String name; |
|
|
|
|
|
|
|
@ -28,6 +28,7 @@ import org.thingsboard.server.common.data.page.PageLink; |
|
|
|
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
import static org.thingsboard.server.dao.entity.AbstractEntityService.checkConstraintViolation; |
|
|
|
import static org.thingsboard.server.dao.service.Validator.validatePageLink; |
|
|
|
|
|
|
|
@Service |
|
|
|
@ -38,7 +39,12 @@ class AiSettingsServiceImpl implements AiSettingsService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public AiSettings save(AiSettings aiSettings) { |
|
|
|
return aiSettingsDao.saveAndFlush(aiSettings.getTenantId(), aiSettings); |
|
|
|
try { |
|
|
|
return aiSettingsDao.saveAndFlush(aiSettings.getTenantId(), aiSettings); |
|
|
|
} catch (Exception e) { |
|
|
|
checkConstraintViolation(e, "ai_settings_name_unq_key", "AI settings record with such name already exists!"); |
|
|
|
throw e; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
@ -957,5 +957,6 @@ CREATE TABLE IF NOT EXISTS ai_settings ( |
|
|
|
name VARCHAR(255) NOT NULL, |
|
|
|
provider VARCHAR(255) NOT NULL, |
|
|
|
model VARCHAR(255) NOT NULL, |
|
|
|
api_key VARCHAR(1000) NOT NULL |
|
|
|
api_key VARCHAR(1000) NOT NULL, |
|
|
|
CONSTRAINT ai_settings_name_unq_key UNIQUE (tenant_id, name) |
|
|
|
); |
|
|
|
|