Spaces:
Running
Running
| """ | |
| 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() | |