-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
56 lines (48 loc) · 1.76 KB
/
schema.sql
File metadata and controls
56 lines (48 loc) · 1.76 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
-- schema.sql - Optimized for RAG-only multimodal support
-- Run: wrangler d1 execute mcp-knowledge-db --remote --file=./schema.sql
CREATE TABLE IF NOT EXISTS documents (
id TEXT PRIMARY KEY,
content TEXT NOT NULL,
title TEXT,
source TEXT,
category TEXT,
chunk_index INTEGER DEFAULT 0,
parent_id TEXT,
word_count INTEGER,
is_image INTEGER DEFAULT 0,
tenant_id TEXT DEFAULT NULL,
created_at TEXT DEFAULT (datetime('now'))
);
CREATE TABLE IF NOT EXISTS keywords (
id INTEGER PRIMARY KEY AUTOINCREMENT,
document_id TEXT NOT NULL,
term TEXT NOT NULL,
term_frequency INTEGER DEFAULT 1,
FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS doc_stats (
id INTEGER PRIMARY KEY CHECK (id = 1),
total_documents INTEGER DEFAULT 0,
avg_doc_length REAL DEFAULT 0
);
CREATE TABLE IF NOT EXISTS term_stats (
term TEXT PRIMARY KEY,
document_frequency INTEGER DEFAULT 1
);
CREATE INDEX IF NOT EXISTS idx_keywords_term ON keywords(term);
CREATE INDEX IF NOT EXISTS idx_keywords_doc ON keywords(document_id);
CREATE INDEX IF NOT EXISTS idx_documents_parent ON documents(parent_id);
CREATE INDEX IF NOT EXISTS idx_documents_image ON documents(is_image);
CREATE INDEX IF NOT EXISTS idx_documents_tenant ON documents(tenant_id);
INSERT OR IGNORE INTO doc_stats (id, total_documents, avg_doc_length) VALUES (1, 0, 0);
-- Licenses table
CREATE TABLE IF NOT EXISTS licenses (
license_key TEXT PRIMARY KEY,
email TEXT,
plan TEXT DEFAULT 'standard',
max_documents INTEGER DEFAULT 10000,
max_queries_per_day INTEGER DEFAULT 1000,
created_at TEXT DEFAULT (datetime('now')),
is_active INTEGER DEFAULT 1
);
CREATE INDEX IF NOT EXISTS idx_licenses_email ON licenses(email);