File size: 936 Bytes
e8a57cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Migration: Add knowledge_graphs table
Run: python3 < this file
"""

import sqlite3
import os

DB_PATH = 'database.db'

def migrate():
    conn = sqlite3.connect(DB_PATH)
    cursor = conn.cursor()
    
    # Create knowledge_graphs table
    cursor.execute("""
        CREATE TABLE IF NOT EXISTS knowledge_graphs (
            session_id TEXT PRIMARY KEY,
            graph_data TEXT,
            created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
            updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
            FOREIGN KEY (session_id) REFERENCES sessions(id) ON DELETE CASCADE
        )
    """)
    
    # Add session_type index for faster lookups
    cursor.execute("""
        CREATE INDEX IF NOT EXISTS idx_sessions_type 
        ON sessions(session_type)
    """)
    
    conn.commit()
    conn.close()
    
    print("✓ Migration completed: knowledge_graphs table created")

if __name__ == '__main__':
    migrate()