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.

fix: Remove ensure_tables.py as v1 databases are not migratable

LearningCircuit07c56eb99a31
diff --git a/src/local_deep_research/database/encrypted_db.py b/src/local_deep_research/database/encrypted_db.py
index 164f6c26f1..1f9651089e 100644
--- a/src/local_deep_research/database/encrypted_db.py
+++ b/src/local_deep_research/database/encrypted_db.py
@@ -287,17 +287,8 @@ class DatabaseManager:
self.connections[username] = engine
# Ensure all tables exist (for completeness during creation)
- # Note: This is now done after the connection is stored to avoid issues
- try:
- from .ensure_tables import (
- ensure_search_history_table,
- ensure_news_tables,
- )
-
- ensure_search_history_table(engine)
- ensure_news_tables(engine)
- except Exception as e:
- logger.warning(f"Could not ensure tables during creation: {e}")
+ # Tables are created by Base.metadata.create_all() above
+ # Future migrations will be handled by Alembic
logger.info(f"Created encrypted database for user {username}")
return engine
@@ -390,17 +381,10 @@ class DatabaseManager:
# Store connection
self.connections[username] = engine
- # Ensure all tables exist (for new tables added after database creation)
- try:
- from .ensure_tables import (
- ensure_search_history_table,
- ensure_news_tables,
- )
-
- ensure_search_history_table(engine)
- ensure_news_tables(engine)
- except Exception as e:
- logger.warning(f"Could not ensure tables: {e}")
+ # Note: Since v1 databases are not migratable, we don't attempt
+ # to add new tables to existing databases. Users will need to
+ # recreate their database to get new features.
+ # Future versions will use Alembic for proper migrations.
logger.info(f"Opened encrypted database for user {username}")
return engine
diff --git a/src/local_deep_research/database/ensure_tables.py b/src/local_deep_research/database/ensure_tables.py
deleted file mode 100644
index e694d36d42..0000000000
--- a/src/local_deep_research/database/ensure_tables.py
+++ /dev/null
@@ -1,76 +0,0 @@
-"""Utilities to ensure database tables exist for existing users."""
-
-from loguru import logger
-from sqlalchemy import inspect, text
-from sqlalchemy.engine import Engine
-from sqlalchemy.schema import CreateTable
-from sqlalchemy.dialects import sqlite
-
-from .models import (
- UserNewsSearchHistory,
- NewsSubscription,
- SubscriptionFolder,
- NewsCard,
- UserRating,
- UserPreference,
- NewsInterest,
-)
-
-
-def ensure_search_history_table(engine: Engine) -> None:
- """Ensure the UserNewsSearchHistory table exists in the database.
-
- This is needed for existing user databases created before this table was added.
- """
- inspector = inspect(engine)
-
- if "user_news_search_history" not in inspector.get_table_names():
- logger.info("Creating missing user_news_search_history table")
-
- # Get the CREATE TABLE statement
- sqlite_dialect = sqlite.dialect()
- create_sql = str(
- CreateTable(UserNewsSearchHistory.__table__).compile(
- dialect=sqlite_dialect
- )
- )
-
- # Execute the CREATE TABLE
- with engine.begin() as conn:
- conn.execute(text(create_sql))
-
- logger.info("user_news_search_history table created successfully")
-
-
-def ensure_news_tables(engine: Engine) -> None:
- """Ensure all news-related tables exist in the user's database."""
- inspector = inspect(engine)
- existing_tables = inspector.get_table_names()
- sqlite_dialect = sqlite.dialect()
-
- # List of news tables to check
- news_tables = [
- ("news_subscriptions", NewsSubscription.__table__),
- ("subscription_folders", SubscriptionFolder.__table__),
- ("news_cards", NewsCard.__table__),
- ("news_user_ratings", UserRating.__table__),
- ("news_user_preferences", UserPreference.__table__),
- ("news_interests", NewsInterest.__table__),
- ]
-
- created_tables = []
-
- with engine.begin() as conn:
- for table_name, table in news_tables:
- if table_name not in existing_tables:
- logger.info(f"Creating missing {table_name} table")
- create_sql = str(
- CreateTable(table).compile(dialect=sqlite_dialect)
- )
- conn.execute(text(create_sql))
- created_tables.append(table_name)
-
- if created_tables:
- logger.info(f"Created news tables: {', '.join(created_tables)}")
- else:
- logger.debug("All news tables already exist")