Files
Profeto/alembic/env.py
T
shangfangjian 0a27b18c27 feat: 足球 LLM 预测服务初始提交
Profeto — 给 LLM 提供数据,让 LLM 预测足球比分。

核心模块:
- FastAPI 后端 + PostgreSQL (SQLAlchemy async)
- 多 Agent LLM 预测 (5 专家 + 终裁)
- 数据采集 (bzzoiro / understat / injuries)
- React 前端 (Vite + Tailwind)

包含:
- 数据源抽象 (DataSource 协议 + 注册表)
- Alembic 数据库迁移
- Prompt 模板 (单/多 Agent)
- 核心路径单元测试
2026-09-09 02:10:47 +08:00

65 lines
1.8 KiB
Python

from logging.config import fileConfig
import sys
from pathlib import Path
from sqlalchemy import engine_from_config, pool
from alembic import context
# 把项目根加入 pythonpath,让 alembic 能找到 src 包
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from src.db.base import Base # noqa: E402
from src.db.models import * # noqa: E402,F401,F403 # 导入所有模型确保注册
from src.core.config import settings # noqa: E402
# this is the Alembic Config object
config = context.config
# 用 settings 的 DATABASE_URL,但转成 sync 驱动
DB_URL = settings.DATABASE_URL
if DB_URL.startswith("postgresql+asyncpg"):
DB_URL = DB_URL.replace("postgresql+asyncpg", "postgresql+psycopg2", 1)
config.set_main_option("sqlalchemy.url", DB_URL)
# Interpret the config file for Python logging.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
target_metadata = Base.metadata
def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode."""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online() -> None:
"""Run migrations in 'online' mode."""
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(connection=connection, target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()