Your Name 4a3c7e7923 refactor: 清理无用模块、修复前后端对齐、添加注册页面
- 删除后端 risk_exceptions 模块(API/Model/Schema/迁移/测试)
- 删除后端 metrics 模块(API/测试)
- 删除后端 ManualTask 模型和相关 Schema
- 修复搜索接口响应缺少 total 字段的问题
- 统一 Platform 枚举(前端去掉后端不支持的 weibo/wechat)
- 新增前端注册页面 /register,登录页添加注册链接

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 14:51:17 +08:00

105 lines
2.0 KiB
Python

"""数据库配置"""
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker
from app.config import settings
# 导入所有模型,确保在创建表时被注册
from app.models.base import Base
from app.models import (
# 用户与组织
User,
UserRole,
Brand,
Agency,
Creator,
# 项目与任务
Project,
Task,
TaskStage,
TaskStatus,
Brief,
# AI 配置
AIConfig,
# 审核
ReviewTask,
# 规则
ForbiddenWord,
WhitelistItem,
Competitor,
# 兼容
Tenant,
)
# 创建异步引擎
engine = create_async_engine(
settings.DATABASE_URL,
echo=settings.DEBUG,
future=True,
)
# 创建异步会话工厂
AsyncSessionLocal = sessionmaker(
engine,
class_=AsyncSession,
expire_on_commit=False,
)
async def get_db():
"""获取数据库会话依赖"""
async with AsyncSessionLocal() as session:
try:
yield session
await session.commit()
except Exception:
await session.rollback()
raise
finally:
await session.close()
async def init_db():
"""初始化数据库(创建所有表)"""
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
async def drop_db():
"""删除所有表(仅用于测试)"""
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.drop_all)
# 导出所有模型,供其他模块使用
__all__ = [
"Base",
"engine",
"AsyncSessionLocal",
"get_db",
"init_db",
"drop_db",
# 用户与组织
"User",
"UserRole",
"Brand",
"Agency",
"Creator",
# 项目与任务
"Project",
"Task",
"TaskStage",
"TaskStatus",
"Brief",
# AI 配置
"AIConfig",
# 审核
"ReviewTask",
# 规则
"ForbiddenWord",
"WhitelistItem",
"Competitor",
# 兼容
"Tenant",
]