AI rule node: make name of the AI settings unique within the scope of the tenant
This commit is contained in:
parent
18c75998ef
commit
e695ce3283
@ -22,5 +22,6 @@ CREATE TABLE ai_settings (
|
|||||||
name VARCHAR(255) NOT NULL,
|
name VARCHAR(255) NOT NULL,
|
||||||
provider VARCHAR(255) NOT NULL,
|
provider VARCHAR(255) NOT NULL,
|
||||||
model 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(
|
@Schema(
|
||||||
requiredMode = Schema.RequiredMode.REQUIRED,
|
requiredMode = Schema.RequiredMode.REQUIRED,
|
||||||
accessMode = Schema.AccessMode.READ_WRITE,
|
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"
|
example = "Default AI Settings"
|
||||||
)
|
)
|
||||||
String name;
|
String name;
|
||||||
|
|||||||
@ -28,6 +28,7 @@ import org.thingsboard.server.common.data.page.PageLink;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.thingsboard.server.dao.entity.AbstractEntityService.checkConstraintViolation;
|
||||||
import static org.thingsboard.server.dao.service.Validator.validatePageLink;
|
import static org.thingsboard.server.dao.service.Validator.validatePageLink;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -38,7 +39,12 @@ class AiSettingsServiceImpl implements AiSettingsService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiSettings save(AiSettings aiSettings) {
|
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
|
@Override
|
||||||
|
|||||||
@ -957,5 +957,6 @@ CREATE TABLE IF NOT EXISTS ai_settings (
|
|||||||
name VARCHAR(255) NOT NULL,
|
name VARCHAR(255) NOT NULL,
|
||||||
provider VARCHAR(255) NOT NULL,
|
provider VARCHAR(255) NOT NULL,
|
||||||
model 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)
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user