🐛 Fix models default value

This commit is contained in:
xtaodada 2024-12-01 22:37:50 +08:00
parent bf5b153001
commit d10f0d4815
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
7 changed files with 38 additions and 30 deletions

View File

@ -29,10 +29,10 @@ class Cookies(SQLModel):
BigInteger(), BigInteger(),
), ),
) )
data: Optional[Dict[str, str]] = Field(sa_column=Column(JSON)) data: Optional[Dict[str, str]] = Field(default=None, sa_column=Column(JSON))
status: Optional[CookiesStatusEnum] = Field(sa_column=Column(Enum(CookiesStatusEnum))) status: Optional[CookiesStatusEnum] = Field(default=None, sa_column=Column(Enum(CookiesStatusEnum)))
region: RegionEnum = Field(sa_column=Column(Enum(RegionEnum))) region: RegionEnum = Field(sa_column=Column(Enum(RegionEnum)))
is_share: Optional[bool] = Field(sa_column=Column(Boolean)) is_share: Optional[bool] = Field(default=True, sa_column=Column(Boolean))
class CookiesDataBase(Cookies, table=True): class CookiesDataBase(Cookies, table=True):

View File

@ -40,11 +40,13 @@ class GachaLogRank(SQLModel, table=True):
"""小保底不歪概率""" """小保底不歪概率"""
score_5: int = Field(sa_column=Column(BigInteger(), default=0)) score_5: int = Field(sa_column=Column(BigInteger(), default=0))
"""保留字段""" """保留字段"""
data: Optional[Dict[str, Any]] = Field(sa_column=Column(JSON)) data: Optional[Dict[str, Any]] = Field(default=None, sa_column=Column(JSON))
time_created: Optional[datetime] = Field( time_created: Optional[datetime] = Field(
sa_column=Column(DateTime, server_default=func.now()) # pylint: disable=E1102 default=None, sa_column=Column(DateTime, server_default=func.now()) # pylint: disable=E1102
) )
time_updated: Optional[datetime] = Field(sa_column=Column(DateTime, onupdate=func.now())) # pylint: disable=E1102 time_updated: Optional[datetime] = Field(
default=None, sa_column=Column(DateTime, onupdate=func.now())
) # pylint: disable=E1102
def update_by_new(self, new_ins: "GachaLogRank"): def update_by_new(self, new_ins: "GachaLogRank"):
self.score_1 = new_ins.score_1 self.score_1 = new_ins.score_1

View File

@ -28,10 +28,10 @@ class Group(SQLModel):
chat_id: int = Field(sa_column=Column(BigInteger(), unique=True)) chat_id: int = Field(sa_column=Column(BigInteger(), unique=True))
type: ChatTypeEnum = Field(sa_column=Column(Enum(ChatTypeEnum))) type: ChatTypeEnum = Field(sa_column=Column(Enum(ChatTypeEnum)))
title: str = Field() title: str = Field()
description: Optional[str] = Field(sa_column=Column(TEXT())) description: Optional[str] = Field(default=None, sa_column=Column(TEXT()))
username: Optional[str] = Field() username: Optional[str] = Field(default=None)
big_photo_id: Optional[str] = Field() big_photo_id: Optional[str] = Field(default=None)
small_photo_id: Optional[str] = Field() small_photo_id: Optional[str] = Field(default=None)
created_at: datetime = Field(sa_column=Column(DateTime(timezone=True))) created_at: datetime = Field(sa_column=Column(DateTime(timezone=True)))
updated_at: datetime = Field(sa_column=Column(DateTime(timezone=True))) updated_at: datetime = Field(sa_column=Column(DateTime(timezone=True)))
is_left: int = Field(sa_column=Column(Integer(), default=0)) is_left: int = Field(sa_column=Column(Integer(), default=0))

View File

@ -14,8 +14,10 @@ class HistoryData(SQLModel, table=True):
user_id: int = Field(sa_column=Column(BigInteger(), primary_key=True, index=True)) user_id: int = Field(sa_column=Column(BigInteger(), primary_key=True, index=True))
data_id: Optional[int] = Field(default=None, sa_column=Column(BigInteger())) data_id: Optional[int] = Field(default=None, sa_column=Column(BigInteger()))
time_created: Optional[datetime] = Field( time_created: Optional[datetime] = Field(
sa_column=Column(DateTime, server_default=func.now()) # pylint: disable=E1102 default=None, sa_column=Column(DateTime, server_default=func.now()) # pylint: disable=E1102
) )
time_updated: Optional[datetime] = Field(sa_column=Column(DateTime, onupdate=func.now())) # pylint: disable=E1102 time_updated: Optional[datetime] = Field(
default=None, sa_column=Column(DateTime, onupdate=func.now())
) # pylint: disable=E1102
type: int = Field(sa_column=Column(Integer(), primary_key=True)) type: int = Field(sa_column=Column(Integer(), primary_key=True))
data: Optional[Dict[str, Any]] = Field(sa_column=Column(JSON)) data: Optional[Dict[str, Any]] = Field(default=None, sa_column=Column(JSON))

View File

@ -80,16 +80,18 @@ class PlayerInfo(SQLModel):
id: Optional[int] = Field(default=None, sa_column=Column(Integer(), primary_key=True, autoincrement=True)) id: Optional[int] = Field(default=None, sa_column=Column(Integer(), primary_key=True, autoincrement=True))
user_id: int = Field(sa_column=Column(BigInteger(), primary_key=True)) user_id: int = Field(sa_column=Column(BigInteger(), primary_key=True))
player_id: int = Field(sa_column=Column(BigInteger(), primary_key=True)) player_id: int = Field(sa_column=Column(BigInteger(), primary_key=True))
nickname: Optional[str] = Field() nickname: Optional[str] = Field(default=None)
signature: Optional[str] = Field() signature: Optional[str] = Field(default=None)
hand_image: Optional[int] = Field() hand_image: Optional[int] = Field(default=None)
name_card: Optional[int] = Field() name_card: Optional[int] = Field(default=None)
extra_data: Optional[ExtraPlayerInfo] = Field(sa_column=Column(ExtraPlayerType)) extra_data: Optional[ExtraPlayerInfo] = Field(default=None, sa_column=Column(ExtraPlayerType))
create_time: Optional[datetime] = Field( create_time: Optional[datetime] = Field(
sa_column=Column(DateTime, server_default=func.now()) # pylint: disable=E1102 default=None, sa_column=Column(DateTime, server_default=func.now()) # pylint: disable=E1102
) )
last_save_time: Optional[datetime] = Field(sa_column=Column(DateTime, onupdate=func.now())) # pylint: disable=E1102 last_save_time: Optional[datetime] = Field(
is_update: Optional[bool] = Field(sa_column=Column(Boolean)) default=None, sa_column=Column(DateTime, onupdate=func.now())
) # pylint: disable=E1102
is_update: Optional[bool] = Field(default=None, sa_column=Column(Boolean))
class PlayerInfoSQLModel(PlayerInfo, table=True): class PlayerInfoSQLModel(PlayerInfo, table=True):

View File

@ -36,9 +36,11 @@ class Task(SQLModel, table=True):
player_id: int = Field(sa_column=Column(BigInteger(), primary_key=True, index=True)) player_id: int = Field(sa_column=Column(BigInteger(), primary_key=True, index=True))
chat_id: Optional[int] = Field(default=None, sa_column=Column(BigInteger())) chat_id: Optional[int] = Field(default=None, sa_column=Column(BigInteger()))
time_created: Optional[datetime] = Field( time_created: Optional[datetime] = Field(
sa_column=Column(DateTime, server_default=func.now()) # pylint: disable=E1102 default=None, sa_column=Column(DateTime, server_default=func.now()) # pylint: disable=E1102
) )
time_updated: Optional[datetime] = Field(sa_column=Column(DateTime, onupdate=func.now())) # pylint: disable=E1102 time_updated: Optional[datetime] = Field(
default=None, sa_column=Column(DateTime, onupdate=func.now())
) # pylint: disable=E1102
type: TaskTypeEnum = Field(sa_column=Column(Enum(TaskTypeEnum), primary_key=True)) type: TaskTypeEnum = Field(sa_column=Column(Enum(TaskTypeEnum), primary_key=True))
status: Optional[TaskStatusEnum] = Field(sa_column=Column(Enum(TaskStatusEnum))) status: Optional[TaskStatusEnum] = Field(default=None, sa_column=Column(Enum(TaskStatusEnum)))
data: Optional[Dict[str, Any]] = Field(sa_column=Column(JSON)) data: Optional[Dict[str, Any]] = Field(default=None, sa_column=Column(JSON))

View File

@ -21,11 +21,11 @@ class User(SQLModel):
__table_args__ = dict(mysql_charset="utf8mb4", mysql_collate="utf8mb4_general_ci") __table_args__ = dict(mysql_charset="utf8mb4", mysql_collate="utf8mb4_general_ci")
id: Optional[int] = Field(default=None, sa_column=Column(Integer(), primary_key=True, autoincrement=True)) id: Optional[int] = Field(default=None, sa_column=Column(Integer(), primary_key=True, autoincrement=True))
user_id: int = Field(sa_column=Column(BigInteger(), unique=True)) user_id: int = Field(sa_column=Column(BigInteger(), unique=True))
permissions: Optional[PermissionsEnum] = Field(sa_column=Column(Enum(PermissionsEnum))) permissions: Optional[PermissionsEnum] = Field(default=None, sa_column=Column(Enum(PermissionsEnum)))
locale: Optional[str] = Field() locale: Optional[str] = Field(default=None)
ban_end_time: Optional[datetime] = Field(sa_column=Column(DateTime(timezone=True))) ban_end_time: Optional[datetime] = Field(default=None, sa_column=Column(DateTime(timezone=True)))
ban_start_time: Optional[datetime] = Field(sa_column=Column(DateTime(timezone=True))) ban_start_time: Optional[datetime] = Field(default=None, sa_column=Column(DateTime(timezone=True)))
is_banned: Optional[int] = Field() is_banned: Optional[int] = Field(default=None)
class UserDataBase(User, table=True): class UserDataBase(User, table=True):