俺又来改数据库哩

This commit is contained in:
suyiiyii 2024-09-13 00:35:14 +08:00
parent 4f73f8a08c
commit af246df222
2 changed files with 17 additions and 6 deletions

View File

@ -79,14 +79,24 @@ class Cookie(Model):
# Cookie 当前的状态
status: Mapped[str] = mapped_column(String(20), default="")
# 使用一次之后,需要的冷却时间
cd: Mapped[int] = mapped_column(default=0)
# 是否是通用 Cookie,默认用于匿名 Cookie
cd_milliseconds: Mapped[int] = mapped_column(default=0)
# 是否是通用 Cookie对所有Target都有效
is_universal: Mapped[bool] = mapped_column(default=False)
# 是否是匿名 Cookie
is_anonymous: Mapped[bool] = mapped_column(default=False)
# 标签,扩展用
tags: Mapped[dict[str, Any]] = mapped_column(JSON().with_variant(JSONB, "postgresql"), default={})
targets: Mapped[list["CookieTarget"]] = relationship(back_populates="cookie")
@property
def cd(self) -> datetime.timedelta:
return datetime.timedelta(milliseconds=self.cd_milliseconds)
@cd.setter
def cd(self, value: datetime.timedelta):
self.cd_milliseconds = int(value.total_seconds() * 1000)
class CookieTarget(Model):
id: Mapped[int] = mapped_column(primary_key=True)

View File

@ -1,8 +1,8 @@
"""empty message
Revision ID: be215495b122
Revision ID: ef796b74b0fe
Revises: f9baef347cc8
Create Date: 2024-09-08 18:12:43.540818
Create Date: 2024-09-13 00:34:08.601438
"""
@ -12,7 +12,7 @@ from sqlalchemy import Text
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = "be215495b122"
revision = "ef796b74b0fe"
down_revision = "f9baef347cc8"
branch_labels = None
depends_on = None
@ -27,8 +27,9 @@ def upgrade() -> None:
sa.Column("content", sa.String(length=1024), nullable=False),
sa.Column("last_usage", sa.DateTime(), nullable=False),
sa.Column("status", sa.String(length=20), nullable=False),
sa.Column("cd", sa.Integer(), nullable=False),
sa.Column("cd_milliseconds", sa.Integer(), nullable=False),
sa.Column("is_universal", sa.Boolean(), nullable=False),
sa.Column("is_anonymous", sa.Boolean(), nullable=False),
sa.Column("tags", sa.JSON().with_variant(postgresql.JSONB(astext_type=Text()), "postgresql"), nullable=False),
sa.PrimaryKeyConstraint("id", name=op.f("pk_nonebot_bison_cookie")),
)