feat: TenantRuntime/Registry——每租户懒建 engine(WAL/pool2)+文件加载器+站点解析
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
+25
-1
@@ -2,7 +2,7 @@ import enum
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from sqlalchemy import String, Text, Boolean, Integer, ForeignKey, JSON, Enum as SAEnum
|
||||
from sqlalchemy import String, Text, Boolean, Integer, ForeignKey, JSON, Enum as SAEnum, text
|
||||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
|
||||
|
||||
|
||||
@@ -159,3 +159,27 @@ class LeadPushLog(Base):
|
||||
default=lambda: datetime.now(timezone.utc),
|
||||
onupdate=lambda: datetime.now(timezone.utc),
|
||||
)
|
||||
|
||||
|
||||
async def ensure_schema(engine) -> None:
|
||||
"""create_all + 旧库加列迁移(自 app/main.py lifespan/_migrate 提取,逻辑逐字等价)。
|
||||
|
||||
jc 上线库(conversations 无 page_token / evaluations 无 correction_count)
|
||||
经此升级;新库 create_all 已含全部列,加列分支空跑。TenantRegistry 懒建
|
||||
每租户库时复用(Phase 1);生产装配见 app/main.py lifespan。
|
||||
"""
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
result = await conn.execute(text("PRAGMA table_info(conversations)"))
|
||||
columns = {row[1] for row in result}
|
||||
if "page_token" not in columns:
|
||||
await conn.execute(text(
|
||||
"ALTER TABLE conversations ADD COLUMN page_token VARCHAR(64)"
|
||||
))
|
||||
|
||||
result = await conn.execute(text("PRAGMA table_info(evaluations)"))
|
||||
columns = {row[1] for row in result}
|
||||
if "correction_count" not in columns:
|
||||
await conn.execute(text(
|
||||
"ALTER TABLE evaluations ADD COLUMN correction_count INTEGER DEFAULT 0"
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user