b597d715c8
后端: - 修复 get_current_user 未校验 is_active,被封禁用户仍可用旧 Token - auth.py 捕获 ValueError 转 HTTPException(验证码错误、账号被封、Token 无效等不再返回 500) - 修正 SMS 每日上限注释(3次 → 10次) - 修复迁移脚本外键引用错误:users.id → mjk_users.id - 新建积分系统 4 张表的迁移(mjk_user_points/batches/transactions/recharge_orders) - pyproject.toml 补充 alembic + psycopg2-binary 依赖 - ruff 格式修复(import 排序等) 前端: - 修复 doRefreshToken 成功后不持久化新 Token 的严重 bug - 修复应用重启后 SSE 不自动重连(收不到踢人通知) - 修复 App.tsx handleLogout 未 await - client.ts 统一从 utils/env 导入 isTauri,默认 base URL 兜底 localhost:8000 - 清理 ~20 个未使用的 hooks/utils/api 模块/组件导出 - 修复所有 ESLint 警告(206 → 0)和 TSC 错误 - 测试通过(5/5) 其他: - 更新 requirements.lock 和 uv.lock
81 lines
2.1 KiB
Python
81 lines
2.1 KiB
Python
"""
|
|
Alembic 环境配置 - PostgreSQL
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
from logging.config import fileConfig
|
|
|
|
from sqlalchemy import engine_from_config, pool
|
|
|
|
from alembic import context
|
|
|
|
# 添加项目路径
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
# 加载环境变量
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
# 导入模型
|
|
from app.db.session import Base
|
|
from app.models.point_batch import PointBatch # noqa
|
|
from app.models.point_recharge_order import PointRechargeOrder # noqa
|
|
from app.models.point_transaction import PointTransaction # noqa
|
|
from app.models.user import User # noqa
|
|
from app.models.user_device import UserDevice # noqa
|
|
from app.models.user_point import UserPoint # noqa
|
|
|
|
# this is the Alembic Config object
|
|
config = context.config
|
|
|
|
# 从环境变量读取数据库 URL
|
|
database_url = os.getenv("DATABASE_URL")
|
|
if database_url:
|
|
# 将 asyncpg 转换为 psycopg2 用于 alembic (同步)
|
|
sync_database_url = database_url.replace("+asyncpg", "")
|
|
config.set_main_option("sqlalchemy.url", sync_database_url)
|
|
|
|
# 设置日志
|
|
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()
|