From a0eba17688695eefb176133742eb7e8a6b3e63d5 Mon Sep 17 00:00:00 2001 From: matevip Date: Mon, 15 Jun 2026 07:37:04 +0800 Subject: [PATCH] fix(db): keep Integer-mapped wiki flag columns as SMALLINT in the PostgreSQL-family tree The blanket SMALLINT->BOOLEAN flag-column conversion over-reached: six wiki columns map to Integer (1/0) entity fields, not Boolean. On vanilla PostgreSQL, reading a BOOLEAN into a JDBC int throws 'Bad value for type int : f', breaking every wiki KB list / SSE chat. Revert only those six back to SMALLINT (V133/V134/ V135/V136/V146 in the PostgreSQL-family tree) with guard comments; genuine Boolean-entity columns stay BOOLEAN. --- .../V133__wiki_agent_page_type_permission.sql | 12 ++++++++---- .../kingbase/V134__wiki_page_type_profile.sql | 7 +++++-- .../kingbase/V135__wiki_layered_knowledge.sql | 4 +++- .../kingbase/V136__wiki_pipeline_runtime.sql | 4 +++- .../kingbase/V146__wiki_kb_watcher_enabled.sql | 5 +++-- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/mateclaw-server/src/main/resources/db/migration/kingbase/V133__wiki_agent_page_type_permission.sql b/mateclaw-server/src/main/resources/db/migration/kingbase/V133__wiki_agent_page_type_permission.sql index f511f8d3..7710d863 100644 --- a/mateclaw-server/src/main/resources/db/migration/kingbase/V133__wiki_agent_page_type_permission.sql +++ b/mateclaw-server/src/main/resources/db/migration/kingbase/V133__wiki_agent_page_type_permission.sql @@ -10,10 +10,14 @@ CREATE TABLE IF NOT EXISTS mate_wiki_agent_page_type_permission ( agent_id BIGINT NOT NULL, kb_id BIGINT NOT NULL, page_type VARCHAR(64) NOT NULL, - can_read BOOLEAN NOT NULL DEFAULT TRUE, - can_create BOOLEAN NOT NULL DEFAULT FALSE, - can_update BOOLEAN NOT NULL DEFAULT FALSE, - can_delete BOOLEAN NOT NULL DEFAULT FALSE, + -- SMALLINT (not BOOLEAN): the entity fields WikiAgentPageTypePermissionEntity + -- .can{Read,Create,Update,Delete} are Integer (1/0). Vanilla PostgreSQL cannot + -- map a BOOLEAN into a JDBC int, so these must stay integer-typed. Do not + -- "normalize" to BOOLEAN to match the other flag columns. + can_read SMALLINT NOT NULL DEFAULT 1, + can_create SMALLINT NOT NULL DEFAULT 0, + can_update SMALLINT NOT NULL DEFAULT 0, + can_delete SMALLINT NOT NULL DEFAULT 0, write_policy VARCHAR(32) NOT NULL DEFAULT 'approval_required', create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, diff --git a/mateclaw-server/src/main/resources/db/migration/kingbase/V134__wiki_page_type_profile.sql b/mateclaw-server/src/main/resources/db/migration/kingbase/V134__wiki_page_type_profile.sql index eaf70f3b..845f9510 100644 --- a/mateclaw-server/src/main/resources/db/migration/kingbase/V134__wiki_page_type_profile.sql +++ b/mateclaw-server/src/main/resources/db/migration/kingbase/V134__wiki_page_type_profile.sql @@ -10,7 +10,10 @@ CREATE TABLE IF NOT EXISTS mate_wiki_page_type_profile ( name VARCHAR(128) NOT NULL, version INT NOT NULL DEFAULT 1, config_json TEXT NOT NULL, - enabled BOOLEAN NOT NULL DEFAULT TRUE, + -- SMALLINT (not BOOLEAN): WikiPageTypeProfileEntity.enabled is Integer (1/0). + -- Vanilla PostgreSQL cannot map a BOOLEAN into a JDBC int. The generated + -- column below compares enabled = 1 accordingly. Do not switch to BOOLEAN. + enabled SMALLINT NOT NULL DEFAULT 1, create_time TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, update_time TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, deleted INT NOT NULL DEFAULT 0, @@ -18,7 +21,7 @@ CREATE TABLE IF NOT EXISTS mate_wiki_page_type_profile ( -- ignores NULL keys for uniqueness, giving "at most one enabled per KB". enabled_kb BIGINT GENERATED ALWAYS AS ( - CASE WHEN enabled = TRUE AND deleted = 0 THEN kb_id ELSE NULL END + CASE WHEN enabled = 1 AND deleted = 0 THEN kb_id ELSE NULL END ) STORED, PRIMARY KEY (id) ); diff --git a/mateclaw-server/src/main/resources/db/migration/kingbase/V135__wiki_layered_knowledge.sql b/mateclaw-server/src/main/resources/db/migration/kingbase/V135__wiki_layered_knowledge.sql index c48baebb..fe6bdd70 100644 --- a/mateclaw-server/src/main/resources/db/migration/kingbase/V135__wiki_layered_knowledge.sql +++ b/mateclaw-server/src/main/resources/db/migration/kingbase/V135__wiki_layered_knowledge.sql @@ -28,7 +28,9 @@ BEGIN SELECT 1 FROM information_schema.columns WHERE table_name = 'mate_wiki_page' AND column_name = 'stale' ) THEN - ALTER TABLE mate_wiki_page ADD COLUMN stale BOOLEAN NOT NULL DEFAULT FALSE; + -- SMALLINT (not BOOLEAN): WikiPageEntity.stale is Integer (1/0). Vanilla + -- PostgreSQL cannot map a BOOLEAN into a JDBC int. Do not switch to BOOLEAN. + ALTER TABLE mate_wiki_page ADD COLUMN stale SMALLINT NOT NULL DEFAULT 0; END IF; END $$; diff --git a/mateclaw-server/src/main/resources/db/migration/kingbase/V136__wiki_pipeline_runtime.sql b/mateclaw-server/src/main/resources/db/migration/kingbase/V136__wiki_pipeline_runtime.sql index c26d05ed..d022e094 100644 --- a/mateclaw-server/src/main/resources/db/migration/kingbase/V136__wiki_pipeline_runtime.sql +++ b/mateclaw-server/src/main/resources/db/migration/kingbase/V136__wiki_pipeline_runtime.sql @@ -10,7 +10,9 @@ CREATE TABLE IF NOT EXISTS mate_wiki_pipeline_definition ( trigger_config_json TEXT, steps_json TEXT NOT NULL, dedup_window_seconds INT NOT NULL DEFAULT 0, - enabled BOOLEAN NOT NULL DEFAULT TRUE, + -- SMALLINT (not BOOLEAN): WikiPipelineDefinitionEntity.enabled is Integer (1/0). + -- Vanilla PostgreSQL cannot map a BOOLEAN into a JDBC int. Do not switch to BOOLEAN. + enabled SMALLINT NOT NULL DEFAULT 1, create_time TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, update_time TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, deleted INT NOT NULL DEFAULT 0 diff --git a/mateclaw-server/src/main/resources/db/migration/kingbase/V146__wiki_kb_watcher_enabled.sql b/mateclaw-server/src/main/resources/db/migration/kingbase/V146__wiki_kb_watcher_enabled.sql index 26bd7640..a6965ac2 100644 --- a/mateclaw-server/src/main/resources/db/migration/kingbase/V146__wiki_kb_watcher_enabled.sql +++ b/mateclaw-server/src/main/resources/db/migration/kingbase/V146__wiki_kb_watcher_enabled.sql @@ -1,6 +1,7 @@ -- Per-KB source-watcher toggle. See the h2 sibling for the prose explanation. -- MySQL INFORMATION_SCHEMA guard converted to plpgsql DO block. --- TINYINT(1) converted to SMALLINT. +-- SMALLINT (not BOOLEAN): WikiKnowledgeBaseEntity.watcherEnabled is Integer (1/0). +-- Vanilla PostgreSQL cannot map a BOOLEAN into a JDBC int. Do not switch to BOOLEAN. DO $$ BEGIN @@ -8,6 +9,6 @@ BEGIN SELECT 1 FROM information_schema.columns WHERE table_name = 'mate_wiki_knowledge_base' AND column_name = 'watcher_enabled' ) THEN - ALTER TABLE mate_wiki_knowledge_base ADD COLUMN watcher_enabled BOOLEAN NOT NULL DEFAULT FALSE; + ALTER TABLE mate_wiki_knowledge_base ADD COLUMN watcher_enabled SMALLINT NOT NULL DEFAULT 0; END IF; END $$;