refactor: removed nullable in models
This commit is contained in:
@ -14,20 +14,19 @@ if TYPE_CHECKING:
|
||||
class Deal(BaseModel, IdMixin, SoftDeleteMixin, CreatedAtMixin):
|
||||
__tablename__ = "deals"
|
||||
|
||||
name: Mapped[str] = mapped_column(nullable=False)
|
||||
lexorank: Mapped[str] = mapped_column(nullable=False)
|
||||
name: Mapped[str] = mapped_column()
|
||||
lexorank: Mapped[str] = mapped_column()
|
||||
|
||||
status_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("statuses.id"),
|
||||
nullable=False,
|
||||
comment="Текущий статус",
|
||||
)
|
||||
status: Mapped["Status"] = relationship()
|
||||
|
||||
board_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("boards.id"), nullable=True, server_default="1"
|
||||
board_id: Mapped[Optional[int]] = mapped_column(
|
||||
ForeignKey("boards.id"), server_default="1"
|
||||
)
|
||||
board: Mapped["Board"] = relationship(back_populates="deals")
|
||||
board: Mapped[Optional["Board"]] = relationship(back_populates="deals")
|
||||
|
||||
status_history: Mapped[list["DealStatusHistory"]] = relationship(
|
||||
back_populates="deal",
|
||||
|
||||
@ -9,17 +9,13 @@ class IdMixin:
|
||||
|
||||
|
||||
class SoftDeleteMixin:
|
||||
is_deleted: Mapped[bool] = mapped_column(
|
||||
default=False,
|
||||
nullable=False,
|
||||
)
|
||||
is_deleted: Mapped[bool] = mapped_column(default=False)
|
||||
|
||||
|
||||
class CreatedAtMixin:
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
default=lambda: datetime.now(timezone.utc),
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
|
||||
@ -27,7 +23,6 @@ class LastModifiedAtMixin:
|
||||
last_modified_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
default=lambda: datetime.now(timezone.utc),
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ if TYPE_CHECKING:
|
||||
class Project(BaseModel, IdMixin, SoftDeleteMixin, CreatedAtMixin):
|
||||
__tablename__ = "projects"
|
||||
|
||||
name: Mapped[str] = mapped_column(nullable=False)
|
||||
name: Mapped[str] = mapped_column()
|
||||
|
||||
boards: Mapped[list["Board"]] = relationship(
|
||||
back_populates="project",
|
||||
|
||||
@ -13,22 +13,21 @@ if TYPE_CHECKING:
|
||||
class Status(BaseModel, IdMixin, SoftDeleteMixin):
|
||||
__tablename__ = "statuses"
|
||||
|
||||
name: Mapped[str] = mapped_column(nullable=False)
|
||||
lexorank: Mapped[str] = mapped_column(nullable=False)
|
||||
name: Mapped[str] = mapped_column()
|
||||
lexorank: Mapped[str] = mapped_column()
|
||||
|
||||
board_id: Mapped[int] = mapped_column(ForeignKey("boards.id"), nullable=False)
|
||||
board_id: Mapped[int] = mapped_column(ForeignKey("boards.id"))
|
||||
board: Mapped["Board"] = relationship(back_populates="statuses")
|
||||
|
||||
|
||||
class DealStatusHistory(BaseModel, IdMixin, CreatedAtMixin):
|
||||
__tablename__ = "status_history"
|
||||
|
||||
deal_id: Mapped[int] = mapped_column(ForeignKey("deals.id"), nullable=False)
|
||||
deal_id: Mapped[int] = mapped_column(ForeignKey("deals.id"))
|
||||
deal: Mapped["Deal"] = relationship(back_populates="status_history")
|
||||
|
||||
from_status_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("statuses.id"),
|
||||
nullable=False,
|
||||
comment="Старый статус",
|
||||
)
|
||||
from_status: Mapped[Status] = relationship(
|
||||
@ -38,7 +37,6 @@ class DealStatusHistory(BaseModel, IdMixin, CreatedAtMixin):
|
||||
|
||||
to_status_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("statuses.id"),
|
||||
nullable=False,
|
||||
comment="Новый статус",
|
||||
)
|
||||
to_status: Mapped[Status] = relationship(
|
||||
|
||||
Reference in New Issue
Block a user