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.9 KB
Raw Blame
"""
Alembic environment for programmatic migration execution.

This environment is designed for per-user encrypted SQLCipher databases.
It receives a connection via config.attributes set by alembic_runner.py.
"""

from alembic import context

# Import models metadata for autogenerate support
from local_deep_research.database.models import Base

# This is the Alembic Config object
config = context.config

# Model metadata for autogenerate
target_metadata = Base.metadata


def run_migrations_offline():
    """Run migrations in 'offline' mode - not supported in this project."""
    raise NotImplementedError(
        "Offline migrations not supported. "
        "Use alembic_runner.run_migrations() for programmatic execution."
    )


def run_migrations_online():
    """
    Run migrations in 'online' mode using the provided connection.

    The connection is passed via config.attributes["connection"] by alembic_runner.py,
    which runs the upgrade inside conn.begin() with SQLite's physical
    transaction already open (see run_migrations), so a failure rolls back
    schema changes as well as data. Because conn.begin() is already active,
    context.begin_transaction() below is a no-op and every revision runs in
    that one transaction.
    """
    connection = config.attributes.get("connection")

    if connection is None:
        raise RuntimeError(
            "No connection provided via config.attributes['connection']. "
            "Use alembic_runner.run_migrations() for programmatic execution."
        )

    context.configure(
        connection=connection,
        target_metadata=target_metadata,
        render_as_batch=True,  # Required for SQLite ALTER TABLE
        compare_type=True,
    )

    with context.begin_transaction():
        context.run_migrations()


if context.is_offline_mode():
    run_migrations_offline()
else:
    run_migrations_online()