diff --git a/server/db/schema/schema_3.ddl b/server/db/schema/schema_3.ddl index 7f51c4f..9005b87 100644 --- a/server/db/schema/schema_3.ddl +++ b/server/db/schema/schema_3.ddl @@ -98,6 +98,176 @@ CREATE INDEX "idx_messages_senderip" ON messages (sender_ip); CREATE INDEX "idx_messages_sendername" ON messages (sender_name); +CREATE VIRTUAL TABLE messages_fts USING fts5 +( + scn_message_id, + sender_user_id, + owner_user_id, + channel_name, + channel_id, + sender_ip, + sender_name, + timestamp_real, + timestamp_client, + title, + content, + priority, + usr_message_id, + + tokenize = unicode61, + content = 'messages', + content_rowid = 'scn_message_id' +); + +CREATE TRIGGER articles_after_insert AFTER INSERT ON messages BEGIN + INSERT INTO messages_fts + ( + rowid, + scn_message_id, + sender_user_id, + owner_user_id, + channel_name, + channel_id, + sender_ip, + sender_name, + timestamp_real, + timestamp_client, + title, + content, + priority, + usr_message_id + ) VALUES ( + new.scn_message_id, + new.scn_message_id, + new.sender_user_id, + new.owner_user_id, + new.channel_name, + new.channel_id, + new.sender_ip, + new.sender_name, + new.timestamp_real, + new.timestamp_client, + new.title, + new.content, + new.priority, + new.usr_message_id + ); +END; + +CREATE TRIGGER articles_fts_after_update AFTER UPDATE ON messages BEGIN + INSERT INTO messages_fts + ( + messages_fts, + rowid, + scn_message_id, + sender_user_id, + owner_user_id, + channel_name, + channel_id, + sender_ip, + sender_name, + timestamp_real, + timestamp_client, + title, + content, + priority, + usr_message_id + ) + VALUES + ( + 'delete', + old.scn_message_id, + old.scn_message_id, + old.sender_user_id, + old.owner_user_id, + old.channel_name, + old.channel_id, + old.sender_ip, + old.sender_name, + old.timestamp_real, + old.timestamp_client, + old.title, + old.content, + old.priority, + old.usr_message_id + ); + INSERT INTO messages_fts + ( + rowid, + scn_message_id, + sender_user_id, + owner_user_id, + channel_name, + channel_id, + sender_ip, + sender_name, + timestamp_real, + timestamp_client, + title, + content, + priority, + usr_message_id + ) + VALUES + ( + new.scn_message_id, + new.scn_message_id, + new.sender_user_id, + new.owner_user_id, + new.channel_name, + new.channel_id, + new.sender_ip, + new.sender_name, + new.timestamp_real, + new.timestamp_client, + new.title, + new.content, + new.priority, + new.usr_message_id + ); +END; + +CREATE TRIGGER articles_fts_after_delete AFTER DELETE ON messages BEGIN + INSERT INTO messages_fts + ( + messages_fts, + rowid, + scn_message_id, + sender_user_id, + owner_user_id, + channel_name, + channel_id, + sender_ip, + sender_name, + timestamp_real, + timestamp_client, + title, + content, + priority, + usr_message_id + ) + VALUES + ( + 'delete', + old.scn_message_id, + old.scn_message_id, + old.sender_user_id, + old.owner_user_id, + old.channel_name, + old.channel_id, + old.sender_ip, + old.sender_name, + old.timestamp_real, + old.timestamp_client, + old.title, + old.content, + old.priority, + old.usr_message_id + ); +END; + + + CREATE TABLE deliveries ( delivery_id INTEGER PRIMARY KEY AUTOINCREMENT,