7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
122 lines
3.8 KiB
Python
122 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Add research_mode column to existing databases.
|
|
This script adds the missing research_mode column to TokenUsage and SearchCall tables.
|
|
"""
|
|
|
|
import os
|
|
import sqlite3
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Add parent directory to path for imports
|
|
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
|
|
|
|
from loguru import logger
|
|
|
|
from local_deep_research.config.paths import get_user_data_directory
|
|
|
|
|
|
def add_research_mode_column(db_path: str):
|
|
"""Add research_mode column to tables if it doesn't exist."""
|
|
try:
|
|
conn = sqlite3.connect(db_path)
|
|
except Exception:
|
|
logger.exception(f"Error connecting to {db_path}")
|
|
return
|
|
try:
|
|
cursor = conn.cursor()
|
|
|
|
# Check if column exists in token_usage
|
|
cursor.execute("PRAGMA table_info(token_usage)")
|
|
columns = [col[1] for col in cursor.fetchall()]
|
|
|
|
if "research_mode" not in columns:
|
|
logger.info(
|
|
f"Adding research_mode column to token_usage in {db_path}"
|
|
)
|
|
cursor.execute(
|
|
"ALTER TABLE token_usage ADD COLUMN research_mode VARCHAR(50)"
|
|
)
|
|
conn.commit()
|
|
else:
|
|
logger.info(
|
|
f"research_mode column already exists in token_usage in {db_path}"
|
|
)
|
|
|
|
# Check if column exists in search_calls
|
|
cursor.execute("PRAGMA table_info(search_calls)")
|
|
columns = [col[1] for col in cursor.fetchall()]
|
|
|
|
if "research_mode" not in columns:
|
|
logger.info(
|
|
f"Adding research_mode column to search_calls in {db_path}"
|
|
)
|
|
cursor.execute(
|
|
"ALTER TABLE search_calls ADD COLUMN research_mode VARCHAR(50)"
|
|
)
|
|
conn.commit()
|
|
else:
|
|
logger.info(
|
|
f"research_mode column already exists in search_calls in {db_path}"
|
|
)
|
|
|
|
logger.info(f"Successfully updated {db_path}")
|
|
except Exception:
|
|
logger.exception(f"Error updating {db_path}")
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
def migrate_all_user_databases():
|
|
"""Migrate all user databases to add research_mode column."""
|
|
# Get base data directory
|
|
from local_deep_research.config.paths import get_data_directory
|
|
|
|
base_dir = get_data_directory()
|
|
|
|
# Look for user directories
|
|
user_dirs = []
|
|
if base_dir.exists():
|
|
for item in base_dir.iterdir():
|
|
if item.is_dir() and item.name.startswith("user_"):
|
|
user_dirs.append(item)
|
|
|
|
if not user_dirs:
|
|
logger.warning("No user directories found")
|
|
return
|
|
|
|
logger.info(f"Found {len(user_dirs)} user directories to migrate")
|
|
|
|
for user_dir in user_dirs:
|
|
db_path = user_dir / f"{user_dir.name}_encrypted.db"
|
|
if db_path.exists():
|
|
logger.info(f"Migrating database for {user_dir.name}")
|
|
add_research_mode_column(str(db_path))
|
|
else:
|
|
logger.warning(f"No database found in {user_dir}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Enable debug logging
|
|
logger.remove()
|
|
# diagnose=False: don't dump frame-local credentials in tracebacks
|
|
# (#4185 / #4384). This script touches user databases and SQLCipher
|
|
# passwords live in frame locals during migration.
|
|
logger.add(sys.stdout, level="INFO", diagnose=False)
|
|
|
|
# Allow unencrypted for testing
|
|
os.environ["LDR_BOOTSTRAP_ALLOW_UNENCRYPTED"] = "true"
|
|
|
|
# Run migration
|
|
migrate_all_user_databases()
|
|
|
|
# Also migrate specific test user if needed
|
|
if len(sys.argv) > 1:
|
|
username = sys.argv[1]
|
|
user_dir = get_user_data_directory(username)
|
|
db_path = user_dir / f"{user_dir.name}_encrypted.db"
|
|
if db_path.exists():
|
|
logger.info(f"Migrating specific user: {username}")
|
|
add_research_mode_column(str(db_path))
|