feat: add context_facts, context_documents, context_chunks tables to schema

This commit is contained in:
pyr0ball 2026-05-13 15:51:19 -07:00
parent 625b55324a
commit 7461953021
3 changed files with 53 additions and 0 deletions

View file

@ -62,6 +62,35 @@ CREATE TABLE IF NOT EXISTS received_bundles (
); );
CREATE INDEX IF NOT EXISTS idx_bundles_bundled ON received_bundles(bundled_at); CREATE INDEX IF NOT EXISTS idx_bundles_bundled ON received_bundles(bundled_at);
CREATE INDEX IF NOT EXISTS idx_bundles_type ON received_bundles(issue_type); CREATE INDEX IF NOT EXISTS idx_bundles_type ON received_bundles(issue_type);
CREATE TABLE IF NOT EXISTS context_facts (
id TEXT PRIMARY KEY,
category TEXT NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
source TEXT,
created_at TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_facts_category ON context_facts(category);
CREATE INDEX IF NOT EXISTS idx_facts_key ON context_facts(key);
CREATE TABLE IF NOT EXISTS context_documents (
id TEXT PRIMARY KEY,
filename TEXT NOT NULL,
doc_type TEXT NOT NULL,
full_text TEXT NOT NULL,
file_size INTEGER,
uploaded_at TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS context_chunks (
id TEXT PRIMARY KEY,
document_id TEXT NOT NULL REFERENCES context_documents(id) ON DELETE CASCADE,
chunk_index INTEGER NOT NULL,
text TEXT NOT NULL,
embedding BLOB
);
CREATE INDEX IF NOT EXISTS idx_chunks_doc ON context_chunks(document_id);
""" """

View file

View file

@ -0,0 +1,24 @@
"""Verify the three new context tables are created by ensure_schema."""
import sqlite3
from pathlib import Path
import pytest
from app.ingest.pipeline import ensure_schema
def test_context_tables_created(tmp_path):
db = tmp_path / "t.db"
ensure_schema(db)
conn = sqlite3.connect(str(db))
tables = {r[0] for r in conn.execute(
"SELECT name FROM sqlite_master WHERE type='table'"
).fetchall()}
conn.close()
assert "context_facts" in tables
assert "context_documents" in tables
assert "context_chunks" in tables
def test_context_schema_idempotent(tmp_path):
db = tmp_path / "t.db"
ensure_schema(db)
ensure_schema(db) # second call must not raise