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(
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import ForeignKey
|
||||
@ -16,10 +15,7 @@ class Client(BaseModel, IdMixin, CreatedAtMixin, SoftDeleteMixin):
|
||||
|
||||
name: Mapped[str] = mapped_column(unique=True, comment="Название клиента")
|
||||
|
||||
company_name: Mapped[str] = mapped_column(
|
||||
nullable=False,
|
||||
comment="Название компании",
|
||||
)
|
||||
company_name: Mapped[str] = mapped_column(comment="Название компании")
|
||||
|
||||
products: Mapped[list["Product"]] = relationship(
|
||||
back_populates="client", lazy="noload"
|
||||
|
||||
@ -62,4 +62,4 @@ class ProductImage(BaseModel, IdMixin):
|
||||
product_id: Mapped[int] = mapped_column(ForeignKey("fulfillment_base_products.id"))
|
||||
product: Mapped["Product"] = relationship(back_populates="images")
|
||||
|
||||
image_url: Mapped[str] = mapped_column(nullable=False)
|
||||
image_url: Mapped[str] = mapped_column()
|
||||
|
||||
@ -50,7 +50,7 @@ class RepCreateMixin(Generic[EntityType, CreateSchemaType], RepBaseMixin[EntityT
|
||||
prepared_data = await self._prepare_create(data)
|
||||
obj = self.entity_class(**prepared_data)
|
||||
self.session.add(obj)
|
||||
await self.session.flash()
|
||||
await self.session.flush()
|
||||
await self.session.refresh(obj)
|
||||
await self._after_create(obj, data)
|
||||
await self.session.commit()
|
||||
|
||||
Reference in New Issue
Block a user