From d6001e3e6f87efddaa891c14bd4aa9651578f0eb Mon Sep 17 00:00:00 2001 From: matevip Date: Sat, 20 Jun 2026 07:23:54 +0800 Subject: [PATCH] fix(db): correct V154 wiki_disabled migration for MySQL and KingbaseES MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cherry-picked V154 used 'ALTER TABLE ... ADD COLUMN IF NOT EXISTS' for MySQL — invalid on MySQL 8.0.x (a MariaDB-only extension) which aborts Flyway at startup. Switch to the INFORMATION_SCHEMA + PREPARE guard the other MySQL migrations use. Also change the KingbaseES column from SMALLINT to BOOLEAN to match the Java 'Boolean wikiDisabled' field and the existing skills_disabled / tools_disabled flags (vanilla PostgreSQL is strict about boolean vs smallint). H2 (already BOOLEAN) is unchanged. --- .../kingbase/V154__agent_wiki_disabled.sql | 2 +- .../mysql/V154__agent_wiki_disabled.sql | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/mateclaw-server/src/main/resources/db/migration/kingbase/V154__agent_wiki_disabled.sql b/mateclaw-server/src/main/resources/db/migration/kingbase/V154__agent_wiki_disabled.sql index 72db6127..62c9db24 100644 --- a/mateclaw-server/src/main/resources/db/migration/kingbase/V154__agent_wiki_disabled.sql +++ b/mateclaw-server/src/main/resources/db/migration/kingbase/V154__agent_wiki_disabled.sql @@ -1,3 +1,3 @@ -- V154: Wiki/knowledge-base opt-out flag on mate_agent (issue #304). -- Mirrors skills_disabled / tools_disabled. Defaults to FALSE. -ALTER TABLE mate_agent ADD COLUMN IF NOT EXISTS wiki_disabled SMALLINT NOT NULL DEFAULT 0; +ALTER TABLE mate_agent ADD COLUMN IF NOT EXISTS wiki_disabled BOOLEAN NOT NULL DEFAULT FALSE; diff --git a/mateclaw-server/src/main/resources/db/migration/mysql/V154__agent_wiki_disabled.sql b/mateclaw-server/src/main/resources/db/migration/mysql/V154__agent_wiki_disabled.sql index abb8131d..aa92cf27 100644 --- a/mateclaw-server/src/main/resources/db/migration/mysql/V154__agent_wiki_disabled.sql +++ b/mateclaw-server/src/main/resources/db/migration/mysql/V154__agent_wiki_disabled.sql @@ -1,3 +1,17 @@ -- V154: Wiki/knowledge-base opt-out flag on mate_agent (issue #304). -- Mirrors skills_disabled / tools_disabled. Defaults to FALSE. -ALTER TABLE mate_agent ADD COLUMN IF NOT EXISTS wiki_disabled TINYINT(1) NOT NULL DEFAULT 0; +-- See the H2 file for context. MySQL 8.0 doesn't support +-- `ADD COLUMN IF NOT EXISTS`, so the existence check goes through +-- INFORMATION_SCHEMA + a prepared statement. +SET @col_exists := ( + SELECT COUNT(*) FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() + AND TABLE_NAME = 'mate_agent' + AND COLUMN_NAME = 'wiki_disabled' +); +SET @ddl := IF(@col_exists = 0, + 'ALTER TABLE mate_agent ADD COLUMN wiki_disabled TINYINT(1) NOT NULL DEFAULT 0', + 'SELECT 1'); +PREPARE stmt FROM @ddl; +EXECUTE stmt; +DEALLOCATE PREPARE stmt;