Add schema migration
Browse files- src/schema.ts +20 -0
src/schema.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export const SCHEMA_MIGRATION = `
|
| 2 |
+
CREATE TABLE IF NOT EXISTS memories_v2 (
|
| 3 |
+
id TEXT PRIMARY KEY,
|
| 4 |
+
text TEXT NOT NULL,
|
| 5 |
+
embedding BLOB NOT NULL,
|
| 6 |
+
type TEXT NOT NULL DEFAULT 'semantic' CHECK (type IN ('episodic', 'semantic', 'procedural')),
|
| 7 |
+
source TEXT NOT NULL DEFAULT 'user' CHECK (source IN ('user', 'assistant')),
|
| 8 |
+
created_at INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000),
|
| 9 |
+
last_accessed_at INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000),
|
| 10 |
+
access_count INTEGER NOT NULL DEFAULT 0,
|
| 11 |
+
importance REAL NOT NULL DEFAULT 0.5 CHECK (importance >= 0 AND importance <= 1),
|
| 12 |
+
conversation_id TEXT,
|
| 13 |
+
metadata TEXT
|
| 14 |
+
);
|
| 15 |
+
CREATE INDEX IF NOT EXISTS idx_memories_type ON memories_v2(type);
|
| 16 |
+
CREATE INDEX IF NOT EXISTS idx_memories_source ON memories_v2(source);
|
| 17 |
+
CREATE INDEX IF NOT EXISTS idx_memories_created ON memories_v2(created_at DESC);
|
| 18 |
+
CREATE INDEX IF NOT EXISTS idx_memories_accessed ON memories_v2(last_accessed_at DESC);
|
| 19 |
+
CREATE INDEX IF NOT EXISTS idx_memories_importance ON memories_v2(importance DESC);
|
| 20 |
+
`;
|