Create or return a persistent GUI chat session.
(
user_id: str,
title: str = "",
session_id: Optional[str] = None,
)
| 287 | timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
| 288 | metadata TEXT, |
| 289 | FOREIGN KEY (paper_id) REFERENCES papers(id) |
| 290 | ) |
| 291 | """) |
| 292 | |
| 293 | # Create task_status table |
| 294 | cursor.execute(""" |
| 295 | CREATE TABLE IF NOT EXISTS task_status ( |
| 296 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 297 | task_id TEXT UNIQUE NOT NULL, |
| 298 | task_type TEXT NOT NULL, |
| 299 | user_id TEXT, |
| 300 | status TEXT NOT NULL, |
| 301 | progress_json TEXT, |
| 302 | started_at TIMESTAMP, |
| 303 | completed_at TIMESTAMP, |
| 304 | error_message TEXT |
| 305 | ) |
| 306 | """) |
| 307 | |
| 308 | _create_chat_tables(cursor) |
| 309 | |
| 310 | # Create indexes |
| 311 | cursor.execute("CREATE INDEX IF NOT EXISTS idx_papers_arxiv ON papers(arxiv_id)") |
| 312 | cursor.execute("CREATE INDEX IF NOT EXISTS idx_papers_doi ON papers(doi)") |
| 313 | cursor.execute("CREATE INDEX IF NOT EXISTS idx_papers_pushed ON papers(pushed) WHERE pushed = FALSE") |
| 314 | cursor.execute("CREATE INDEX IF NOT EXISTS idx_behavior_user ON behavior_logs(user_id)") |
| 315 | cursor.execute("CREATE INDEX IF NOT EXISTS idx_behavior_push ON behavior_logs(push_id)") |
| 316 | cursor.execute("CREATE INDEX IF NOT EXISTS idx_behavior_timestamp ON behavior_logs(timestamp)") |
| 317 | |
| 318 | conn.commit() |
| 319 | conn.close() |
| 320 | print("Database tables created successfully.") |
| 321 | |
| 322 | |
| 323 | # ============== Chat History Operations ============== |
| 324 | |
| 325 | def ensure_chat_tables() -> None: |
| 326 | """Ensure persistent GUI chat history tables exist for upgraded databases.""" |
| 327 | conn = get_connection() |
| 328 | cursor = conn.cursor() |
| 329 | _create_chat_tables(cursor) |
no test coverage detected