@@ -43,15 +43,45 @@ CREATE TABLE IF NOT EXISTS processed_messages (
4343 processing_time INTERVAL,
4444 delivery_time INTERVAL,
4545 conversation_id TEXT,
46- query tsvector GENERATED ALWAYS AS (
47- setweight(to_tsvector('english', coalesce(headers::text, '')), 'A') ||
48- setweight(to_tsvector('english', coalesce(body::text, '')), 'B')
49- ) STORED
46+ query tsvector
5047 );" , connection ) )
5148 {
5249 await cmd . ExecuteNonQueryAsync ( cancellationToken ) ;
5350 }
5451
52+ // Create trigger for full text search
53+ using ( var cmd = new NpgsqlCommand ( @"
54+ CREATE OR REPLACE FUNCTION processed_messages_tsvector_update() RETURNS trigger AS $$
55+ BEGIN
56+ NEW.query :=
57+ setweight(to_tsvector('english', coalesce(NEW.headers::text, '')), 'A') ||
58+ setweight(to_tsvector('english', coalesce(convert_from(NEW.body, 'UTF8'), '')), 'B');
59+ RETURN NEW;
60+ END
61+ $$ LANGUAGE plpgsql;
62+
63+ CREATE TRIGGER processed_messages_tsvector_trigger
64+ BEFORE INSERT OR UPDATE ON processed_messages
65+ FOR EACH ROW EXECUTE FUNCTION processed_messages_tsvector_update();" , connection ) )
66+ {
67+ await cmd . ExecuteNonQueryAsync ( cancellationToken ) ;
68+ }
69+ // Create index on processed_messages for specified columns
70+ using ( var cmd = new NpgsqlCommand ( @"
71+ CREATE INDEX IF NOT EXISTS idx_processed_messages_multi ON processed_messages (
72+ message_id,
73+ time_sent,
74+ receiving_endpoint_name,
75+ critical_time,
76+ processing_time,
77+ delivery_time,
78+ conversation_id,
79+ is_system_message
80+ );" , connection ) )
81+ {
82+ await cmd . ExecuteNonQueryAsync ( cancellationToken ) ;
83+ }
84+
5585 // Create saga_snapshots table
5686 using ( var cmd = new NpgsqlCommand ( @"
5787 CREATE TABLE IF NOT EXISTS saga_snapshots (
0 commit comments