-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
64 lines (55 loc) · 2.42 KB
/
Copy pathschema.sql
File metadata and controls
64 lines (55 loc) · 2.42 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
-- SQLite Memory MCP — Schema
-- Replaces @modelcontextprotocol/server-memory (JSONL)
-- Features: ACID, FTS5 ranked search, timestamps, archival
PRAGMA journal_mode=WAL;
PRAGMA foreign_keys=ON;
-- Core tables
CREATE TABLE IF NOT EXISTS entities (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE NOT NULL,
entity_type TEXT NOT NULL,
created_at TEXT DEFAULT (datetime('now')),
updated_at TEXT DEFAULT (datetime('now'))
);
CREATE TABLE IF NOT EXISTS observations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
entity_id INTEGER NOT NULL REFERENCES entities(id) ON DELETE CASCADE,
content TEXT NOT NULL,
created_at TEXT DEFAULT (datetime('now')),
archived INTEGER DEFAULT 0
);
CREATE TABLE IF NOT EXISTS relations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
from_entity_id INTEGER NOT NULL REFERENCES entities(id) ON DELETE CASCADE,
to_entity_id INTEGER NOT NULL REFERENCES entities(id) ON DELETE CASCADE,
relation_type TEXT NOT NULL,
created_at TEXT DEFAULT (datetime('now')),
UNIQUE(from_entity_id, to_entity_id, relation_type)
);
-- FTS5 full-text search on observations
CREATE VIRTUAL TABLE IF NOT EXISTS observations_fts USING fts5(
content,
content='observations',
content_rowid='id'
);
-- Triggers to keep FTS in sync with observations table
CREATE TRIGGER IF NOT EXISTS obs_ai AFTER INSERT ON observations BEGIN
INSERT INTO observations_fts(rowid, content) VALUES (new.id, new.content);
END;
CREATE TRIGGER IF NOT EXISTS obs_ad AFTER DELETE ON observations BEGIN
INSERT INTO observations_fts(observations_fts, rowid, content)
VALUES('delete', old.id, old.content);
END;
CREATE TRIGGER IF NOT EXISTS obs_au AFTER UPDATE ON observations BEGIN
INSERT INTO observations_fts(observations_fts, rowid, content)
VALUES('delete', old.id, old.content);
INSERT INTO observations_fts(rowid, content) VALUES (new.id, new.content);
END;
-- Indexes for common queries
CREATE INDEX IF NOT EXISTS idx_obs_entity ON observations(entity_id);
CREATE INDEX IF NOT EXISTS idx_obs_created ON observations(created_at DESC);
CREATE INDEX IF NOT EXISTS idx_obs_archived ON observations(archived);
CREATE INDEX IF NOT EXISTS idx_entities_type ON entities(entity_type);
CREATE INDEX IF NOT EXISTS idx_entities_name ON entities(name);
CREATE INDEX IF NOT EXISTS idx_relations_from ON relations(from_entity_id);
CREATE INDEX IF NOT EXISTS idx_relations_to ON relations(to_entity_id);