Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

1.7 KB
Raw Blame
"""Tests for migration 0043: Zotero sync result count columns."""

from alembic import command
from alembic.config import Config
from alembic.script import ScriptDirectory
from sqlalchemy import create_engine, inspect

from local_deep_research.database.alembic_runner import (
    get_alembic_config,
    get_migrations_dir,
    run_migrations,
)

COUNT_COLUMNS = {
    "last_imported_count",
    "last_updated_count",
    "last_removed_count",
    "last_skipped_count",
    "last_error_count",
}


def _columns(engine):
    return {
        c["name"]: c for c in inspect(engine).get_columns("zotero_sync_state")
    }


def _run_alembic(engine, direction, target):
    config = get_alembic_config(engine)
    with engine.connect() as conn:
        with conn.begin():
            config.attributes["connection"] = conn
            getattr(command, direction)(config, target)


def test_0043_chains_after_0042():
    config = Config()
    config.set_main_option("script_location", str(get_migrations_dir()))
    script = ScriptDirectory.from_config(config)
    assert script.get_revision("0043").down_revision == "0042"


def test_upgrade_adds_nullable_count_columns(tmp_path):
    engine = create_engine(f"sqlite:///{tmp_path / 't.db'}")
    run_migrations(engine)
    cols = _columns(engine)
    assert COUNT_COLUMNS <= set(cols)
    assert all(cols[name]["nullable"] for name in COUNT_COLUMNS)
    engine.dispose()


def test_downgrade_removes_count_columns(tmp_path):
    engine = create_engine(f"sqlite:///{tmp_path / 't.db'}")
    run_migrations(engine)
    _run_alembic(engine, "downgrade", "0042")
    assert not COUNT_COLUMNS & set(_columns(engine))
    _run_alembic(engine, "upgrade", "0043")
    assert COUNT_COLUMNS <= set(_columns(engine))
    engine.dispose()