54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
from sqlalchemy import BigInteger, Boolean, ForeignKey, Numeric, String, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.enums.resource_capacity import ResourceCapacityUnitEnum
|
|
from app.models.base import Base, TimestampMixin
|
|
|
|
|
|
class UserResourceCapacityConfig(Base, TimestampMixin):
|
|
"""用户个人生成资源容量配置。存在记录即代表用户配置已单独设置。"""
|
|
|
|
__tablename__ = "user_resource_capacity_configs"
|
|
__table_args__ = (
|
|
UniqueConstraint("user_id", name="uq_user_resource_capacity_configs_user"),
|
|
)
|
|
|
|
id: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
user_id: Mapped[str] = mapped_column(
|
|
String(32),
|
|
ForeignKey("users.id", ondelete="CASCADE"),
|
|
index=True,
|
|
nullable=False,
|
|
comment="用户ID",
|
|
)
|
|
enabled: Mapped[bool] = mapped_column(
|
|
Boolean,
|
|
default=False,
|
|
server_default="false",
|
|
nullable=False,
|
|
comment="是否启用该用户个人容量限制",
|
|
)
|
|
limit_value: Mapped[float] = mapped_column(
|
|
Numeric(18, 3),
|
|
default=1,
|
|
server_default="1",
|
|
nullable=False,
|
|
comment="容量数值,最小1,最多3位小数",
|
|
)
|
|
limit_unit: Mapped[str] = mapped_column(
|
|
String(8),
|
|
default=ResourceCapacityUnitEnum.GB.value,
|
|
server_default=ResourceCapacityUnitEnum.GB.value,
|
|
nullable=False,
|
|
comment="容量单位:MB/GB/TB",
|
|
)
|
|
limit_bytes: Mapped[int] = mapped_column(
|
|
BigInteger,
|
|
default=1024 * 1024 * 1024,
|
|
server_default=str(1024 * 1024 * 1024),
|
|
nullable=False,
|
|
comment="换算后的容量字节数",
|
|
)
|