"""运营可配置项(把 rewards.py 等硬编码规则挪到 DB,运营后台可改)。 key 是配置标识(见 app.core.config_schema.CONFIG_DEFS),value 用 JSON 存任意值(int/list/dict)。 表里没有的 key,业务读配置时 fallback 到 CONFIG_DEFS 默认值(= 原 rewards 常量), 所以**空表 = 现有行为完全不变**。admin 改某项 → 写一行 → 业务下次读到新值(跨进程一致)。 """ from __future__ import annotations from datetime import datetime from typing import Any from sqlalchemy import JSON, DateTime, Integer, String, func from sqlalchemy.dialects.postgresql import JSONB from sqlalchemy.orm import Mapped, mapped_column from app.db.base import Base _JSON = JSON().with_variant(JSONB(), "postgresql") class AppConfig(Base): __tablename__ = "app_config" key: Mapped[str] = mapped_column(String(64), primary_key=True) value: Mapped[Any] = mapped_column(_JSON, nullable=False) updated_by_admin_id: Mapped[int | None] = mapped_column(Integer, nullable=True) updated_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False ) def __repr__(self) -> str: # pragma: no cover return f""