33 lines
1.8 KiB
Python
33 lines
1.8 KiB
Python
from datetime import datetime, timezone
|
|
from typing import Optional
|
|
from sqlalchemy import Integer, String, Boolean, DateTime, Text
|
|
from sqlalchemy.orm import mapped_column, Mapped
|
|
from app.database import Base
|
|
|
|
|
|
class Upstream(Base):
|
|
__tablename__ = "upstreams"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
|
|
name: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
base_url: Mapped[str] = mapped_column(String(512), nullable=False)
|
|
api_prefix: Mapped[str] = mapped_column(String(128), default="/api/v1")
|
|
# none | bearer | api_key | login_password
|
|
auth_type: Mapped[str] = mapped_column(String(32), default="login_password")
|
|
# JSON: {"email":"..","password":".."} or {"token":".."} etc.
|
|
auth_config_json: Mapped[str] = mapped_column(Text, default="{}")
|
|
rate_endpoint: Mapped[str] = mapped_column(String(256), default="/groups/rates")
|
|
groups_endpoint: Mapped[str] = mapped_column(String(256), default="/groups/available")
|
|
enabled: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
check_interval_seconds: Mapped[int] = mapped_column(Integer, default=600)
|
|
timeout_seconds: Mapped[int] = mapped_column(Integer, default=30)
|
|
# unknown | healthy | unhealthy
|
|
last_status: Mapped[str] = mapped_column(String(32), default="unknown")
|
|
last_checked_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
|
last_error: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
consecutive_failures: Mapped[int] = mapped_column(Integer, default=0)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=lambda: datetime.now(timezone.utc))
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc)
|
|
)
|