-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschema.sql
More file actions
31 lines (26 loc) · 1.19 KB
/
schema.sql
File metadata and controls
31 lines (26 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
fullname TEXT NOT NULL,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS post (
id INTEGER PRIMARY KEY AUTOINCREMENT,
author_id INTEGER NOT NULL DEFAULT 1,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
slug varchar(20) NOT NULL DEFAULT (printf('%d', CAST((julianday('now') - 2440587.5) * 86400 AS INTEGER))) UNIQUE,
content TEXT NOT NULL
);
-- Create a virtual table for full-text search
CREATE VIRTUAL TABLE IF NOT EXISTS post_fts USING fts5(content, content='post', content_rowid='id');
-- Create triggers to keep the FTS index up to date
CREATE TRIGGER IF NOT EXISTS post_ai AFTER INSERT ON post BEGIN
INSERT INTO post_fts(rowid, content) VALUES (new.id, new.content);
END;
CREATE TRIGGER IF NOT EXISTS post_ad AFTER DELETE ON post BEGIN
INSERT INTO post_fts(post_fts, rowid, content) VALUES('delete', old.id, old.content);
END;
CREATE TRIGGER IF NOT EXISTS post_au AFTER UPDATE ON post BEGIN
INSERT INTO post_fts(post_fts, rowid, content) VALUES('delete', old.id, old.content);
INSERT INTO post_fts(rowid, content) VALUES (new.id, new.content);
END;