Add Topics and TopicsFts

pull/1323/head
lihenggui 2 years ago
parent 68ca447076
commit 2434f16495

@ -3,7 +3,7 @@ CREATE TABLE news_resources_topics (
topic_id TEXT NOT NULL,
PRIMARY KEY (news_resource_id, topic_id),
FOREIGN KEY (news_resource_id) REFERENCES news_resources(id) ON DELETE CASCADE,
FOREIGN KEY (topic_id) REFERENCES TopicEntity(id) ON DELETE CASCADE
FOREIGN KEY (topic_id) REFERENCES topics(id) ON DELETE CASCADE
);
CREATE INDEX idx_news_resource_id ON news_resources_topics(news_resource_id);

@ -0,0 +1,8 @@
CREATE TABLE topics (
id TEXT PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
short_description TEXT NOT NULL,
long_description TEXT NOT NULL DEFAULT '',
url TEXT NOT NULL DEFAULT '',
image_url TEXT NOT NULL DEFAULT ''
);

@ -0,0 +1,27 @@
CREATE VIRTUAL TABLE IF NOT EXISTS topics_fts
USING FTS4(
topic_id TEXT,
name TEXT,
short_description TEXT,
long_description TEXT
);
CREATE TRIGGER IF NOT EXISTS topics_ai AFTER INSERT ON topics
BEGIN
INSERT INTO topics_fts (topic_id, name, short_description, long_description)
VALUES (new.id, new.name, new.short_description, new.long_description);
END;
CREATE TRIGGER IF NOT EXISTS topics_ad AFTER DELETE ON topics
BEGIN
DELETE FROM topics_fts WHERE topic_id = old.id;
END;
CREATE TRIGGER IF NOT EXISTS topics_au AFTER UPDATE ON topics
BEGIN
UPDATE topics_fts SET
name = new.name,
short_description = new.short_description,
long_description = new.long_description
WHERE topic_id = new.id;
END;
Loading…
Cancel
Save