Skip to content

fix(#540): change ModelConfig.isActive/proxyEnabled from Boolean to Integer - #631

Open
wylovelyi wants to merge 10 commits into
spring-ai-alibaba:mainfrom
wylovelyi:fix/issue-540-modelconfig-integer
Open

wylovelyi wants to merge 10 commits into
spring-ai-alibaba:mainfrom
wylovelyi:fix/issue-540-modelconfig-integer

Conversation

@wylovelyi

Copy link
Copy Markdown

What this PR does

Closes #540 — changes ModelConfig.isActive and ModelConfig.proxyEnabled from Boolean to Integer, to stay consistent with sibling fields (isDeleted, isRecall, AgentDatasource.isActive) and to make future DB migration to PostgreSQL easier (PostgreSQL does not auto-cast Integer↔Boolean).

Key design decisions

  • Entity fields → Integer: ModelConfig.isActive (0/1) and proxyEnabled (0/1).
  • DTO stays Boolean: the REST JSON contract is unchanged, so the frontend is not affected. The translation between Integer (DB) and Boolean (API) is done in ModelConfigConverter.
  • SQL columns widened: is_active and proxy_enabled changed from tinyint(1) DEFAULT '0' to int(11) DEFAULT '0' in both schema.sql and schema-h2.sql. MyBatis auto-maps the columns to Integer.

Files changed

File Change
.../entity/ModelConfig.java isActive/proxyEnabled field type Boolean → Integer
.../converter/ModelConfigConverter.java Integer ↔ Boolean translation in both directions
.../service/impl/ModelConfigDataServiceImpl.java truthiness check Boolean.TRUE.equals(...) → != null && == 1; write 1/0
.../service/ModelConfigOpsService.java fix latent bug: Boolean.TRUE.equals(Integer) is always false, so an activated config never refreshed the in-memory model on update → changed to != null && == 1
.../mapper/ModelConfigConverterTest.java assertions updated to Integer (0/1)
.../service/ModelConfigDataServiceImplTest.java assertions updated to Integer (0/1)
db/schema.sql column types widened
db/schema-h2.sql column types widened (test DB)

Notes

  • The ModelConfigOpsService fix is a real correctness improvement uncovered while migrating the type: with Integer fields, Boolean.TRUE.equals(integerValue) returns false permanently, which would silently skip reloading the active model after an update. Worth merging regardless of the type change itself.
  • No behavior change for API consumers; existing true/false payloads still work.

@wylovelyi

Copy link
Copy Markdown
Author

@zxuexingzhijie 你好,这个 PR 把 ModelConfig.isActive/proxyEnabled 从 Boolean 改为 Integer(#540)。准备好 review 了,方便时帮忙看一下,谢谢!

…model_config columns to int(11)

Signed-off-by: wylovelyi <wylovelyi@users.noreply.github.com>
@wylovelyi

Copy link
Copy Markdown
Author

Pushed a follow-up for the existing-deployment migration gap (P2 from review).

spring.sql.init.mode defaults to never, and schema.sql uses CREATE TABLE IF NOT EXISTS, so an already-created model_config table never gets its is_active / proxy_enabled columns converted from tinyint(1) to int(11) — the Java Integer mapping still works (tinyint reads fine into Integer) but the schema change from this PR never takes effect on existing databases.

Fix: appended an idempotent ALTER TABLE model_config MODIFY COLUMN ... int(11) block to data-agent-management/src/main/resources/sql/schema.sql. It is safe to re-run (no-op on a fresh schema where the columns are already int(11); converts them on an existing schema). It executes when the app is started with DATA_AGENT_DATASOURCE_SQL_INIT=always, or it can be run manually once against an existing database. The H2 test schema (sql/h2/schema-h2.sql) is left untouched since the test database is recreated fresh each run and already has the int(11) columns.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ModelConfig实体中isActive、proxyEnabled两个属性值建议改成Integer类型

1 participant