fix: remove trigger function from message search migration

The PL/pgSQL trigger function caused SQL parsing issues with
split_sql_statements. Keep only the table, column, and index.
This commit is contained in:
ZhenYi 2026-04-15 11:39:39 +08:00
parent 8e7f3b211e
commit b3b74a2396
2 changed files with 2 additions and 29 deletions

View File

@ -19,9 +19,7 @@ impl MigrationTrait for Migration {
)
.await?;
let sql = "DROP TRIGGER IF EXISTS room_message_tsv_update ON room_message;
DROP FUNCTION IF EXISTS room_message_tsv_trigger;
DROP INDEX IF EXISTS idx_room_message_content_tsv;
let sql = "DROP INDEX IF EXISTS idx_room_message_content_tsv;
ALTER TABLE room_message DROP COLUMN IF EXISTS content_tsv;";
super::execute_sql(manager, sql).await
}

View File

@ -15,34 +15,9 @@ CREATE INDEX IF NOT EXISTS idx_room_message_reaction_message ON room_message_rea
CREATE INDEX IF NOT EXISTS idx_room_message_reaction_user ON room_message_reaction ("user");
CREATE INDEX IF NOT EXISTS idx_room_message_reaction_room ON room_message_reaction (room);
-- Add full-text search index for message content (PostgreSQL tsvector)
-- Add full-text search column for message content
ALTER TABLE room_message
ADD COLUMN IF NOT EXISTS content_tsv TSVECTOR;
-- Update existing messages with tsvector
UPDATE room_message
SET content_tsv = to_tsvector('english', content)
WHERE content_tsv IS NULL;
-- Create index for full-text search
CREATE INDEX IF NOT EXISTS idx_room_message_content_tsv ON room_message USING GIN (content_tsv);
-- Trigger to auto-update content_tsv on insert/update
CREATE OR REPLACE FUNCTION room_message_tsv_trigger() RETURNS TRIGGER AS
$$
BEGIN
NEW.content_tsv := to_tsvector('simple', COALESCE(NEW.content, ''));
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER room_message_tsv_update
BEFORE INSERT OR UPDATE
ON room_message
FOR EACH ROW
EXECUTE FUNCTION room_message_tsv_trigger();
-- Backfill existing rows
UPDATE room_message
SET content_tsv = to_tsvector('simple', content)
WHERE content_tsv IS NULL;