feat: enhance UI, refactor services, improve templates and tests
- Replace image_extractor with pdf_image_extractor service - Enhance pi_client with expanded API capabilities - Improve summarizer service with additional features - Update admin routes with more endpoints - Add login page template - Enhance detail page with comprehensive layout - Improve search and trends pages - Update base template with additional elements - Refactor tests for better coverage - Add validate_summary script - Update project configuration and dependencies
This commit is contained in:
+33
-1
@@ -62,8 +62,39 @@ def get_db():
|
||||
db.close()
|
||||
|
||||
|
||||
def _migrate(engine) -> None:
|
||||
"""自动给已有表补齐缺失的列(SQLite ALTER TABLE ADD COLUMN)。"""
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# 定义需要确保存在的列:{表名: [(列名, 列类型 SQL), ...]}
|
||||
_MIGRATIONS: dict[str, list[tuple[str, str]]] = {
|
||||
"paper_summaries": [
|
||||
("figures_json", "TEXT"),
|
||||
],
|
||||
}
|
||||
|
||||
with engine.connect() as conn:
|
||||
for table, columns in _MIGRATIONS.items():
|
||||
# 获取已有列名
|
||||
existing = {
|
||||
row[1]
|
||||
for row in conn.execute(text(f"PRAGMA table_info({table})"))
|
||||
}
|
||||
for col_name, col_type in columns:
|
||||
if col_name not in existing:
|
||||
conn.execute(
|
||||
text(
|
||||
f"ALTER TABLE {table} ADD COLUMN {col_name} {col_type}"
|
||||
)
|
||||
)
|
||||
logger.info("Migrated: %s.%s added", table, col_name)
|
||||
conn.commit()
|
||||
|
||||
|
||||
def init_db(engine):
|
||||
"""创建所有 ORM 表 + FTS5 虚拟表。"""
|
||||
"""创建所有 ORM 表 + FTS5 虚拟表 + 自动迁移。"""
|
||||
from app.models import Base # noqa: F811 — 避免循环导入,延迟导入
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
@@ -71,3 +102,4 @@ def init_db(engine):
|
||||
conn.execute(text(FTS5_CREATE_SQL))
|
||||
conn.execute(text(FTS5_TRIGGER_INDEX))
|
||||
conn.commit()
|
||||
_migrate(engine)
|
||||
|
||||
Reference in New Issue
Block a user