refactor: removed nullable in models
This commit is contained in:
@ -14,20 +14,19 @@ if TYPE_CHECKING:
|
|||||||
class Deal(BaseModel, IdMixin, SoftDeleteMixin, CreatedAtMixin):
|
class Deal(BaseModel, IdMixin, SoftDeleteMixin, CreatedAtMixin):
|
||||||
__tablename__ = "deals"
|
__tablename__ = "deals"
|
||||||
|
|
||||||
name: Mapped[str] = mapped_column(nullable=False)
|
name: Mapped[str] = mapped_column()
|
||||||
lexorank: Mapped[str] = mapped_column(nullable=False)
|
lexorank: Mapped[str] = mapped_column()
|
||||||
|
|
||||||
status_id: Mapped[int] = mapped_column(
|
status_id: Mapped[int] = mapped_column(
|
||||||
ForeignKey("statuses.id"),
|
ForeignKey("statuses.id"),
|
||||||
nullable=False,
|
|
||||||
comment="Текущий статус",
|
comment="Текущий статус",
|
||||||
)
|
)
|
||||||
status: Mapped["Status"] = relationship()
|
status: Mapped["Status"] = relationship()
|
||||||
|
|
||||||
board_id: Mapped[int] = mapped_column(
|
board_id: Mapped[Optional[int]] = mapped_column(
|
||||||
ForeignKey("boards.id"), nullable=True, server_default="1"
|
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(
|
status_history: Mapped[list["DealStatusHistory"]] = relationship(
|
||||||
back_populates="deal",
|
back_populates="deal",
|
||||||
|
|||||||
@ -9,17 +9,13 @@ class IdMixin:
|
|||||||
|
|
||||||
|
|
||||||
class SoftDeleteMixin:
|
class SoftDeleteMixin:
|
||||||
is_deleted: Mapped[bool] = mapped_column(
|
is_deleted: Mapped[bool] = mapped_column(default=False)
|
||||||
default=False,
|
|
||||||
nullable=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class CreatedAtMixin:
|
class CreatedAtMixin:
|
||||||
created_at: Mapped[datetime] = mapped_column(
|
created_at: Mapped[datetime] = mapped_column(
|
||||||
DateTime(timezone=True),
|
DateTime(timezone=True),
|
||||||
default=lambda: datetime.now(timezone.utc),
|
default=lambda: datetime.now(timezone.utc),
|
||||||
nullable=False,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -27,7 +23,6 @@ class LastModifiedAtMixin:
|
|||||||
last_modified_at: Mapped[datetime] = mapped_column(
|
last_modified_at: Mapped[datetime] = mapped_column(
|
||||||
DateTime(timezone=True),
|
DateTime(timezone=True),
|
||||||
default=lambda: datetime.now(timezone.utc),
|
default=lambda: datetime.now(timezone.utc),
|
||||||
nullable=False,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ if TYPE_CHECKING:
|
|||||||
class Project(BaseModel, IdMixin, SoftDeleteMixin, CreatedAtMixin):
|
class Project(BaseModel, IdMixin, SoftDeleteMixin, CreatedAtMixin):
|
||||||
__tablename__ = "projects"
|
__tablename__ = "projects"
|
||||||
|
|
||||||
name: Mapped[str] = mapped_column(nullable=False)
|
name: Mapped[str] = mapped_column()
|
||||||
|
|
||||||
boards: Mapped[list["Board"]] = relationship(
|
boards: Mapped[list["Board"]] = relationship(
|
||||||
back_populates="project",
|
back_populates="project",
|
||||||
|
|||||||
@ -13,22 +13,21 @@ if TYPE_CHECKING:
|
|||||||
class Status(BaseModel, IdMixin, SoftDeleteMixin):
|
class Status(BaseModel, IdMixin, SoftDeleteMixin):
|
||||||
__tablename__ = "statuses"
|
__tablename__ = "statuses"
|
||||||
|
|
||||||
name: Mapped[str] = mapped_column(nullable=False)
|
name: Mapped[str] = mapped_column()
|
||||||
lexorank: Mapped[str] = mapped_column(nullable=False)
|
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")
|
board: Mapped["Board"] = relationship(back_populates="statuses")
|
||||||
|
|
||||||
|
|
||||||
class DealStatusHistory(BaseModel, IdMixin, CreatedAtMixin):
|
class DealStatusHistory(BaseModel, IdMixin, CreatedAtMixin):
|
||||||
__tablename__ = "status_history"
|
__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")
|
deal: Mapped["Deal"] = relationship(back_populates="status_history")
|
||||||
|
|
||||||
from_status_id: Mapped[int] = mapped_column(
|
from_status_id: Mapped[int] = mapped_column(
|
||||||
ForeignKey("statuses.id"),
|
ForeignKey("statuses.id"),
|
||||||
nullable=False,
|
|
||||||
comment="Старый статус",
|
comment="Старый статус",
|
||||||
)
|
)
|
||||||
from_status: Mapped[Status] = relationship(
|
from_status: Mapped[Status] = relationship(
|
||||||
@ -38,7 +37,6 @@ class DealStatusHistory(BaseModel, IdMixin, CreatedAtMixin):
|
|||||||
|
|
||||||
to_status_id: Mapped[int] = mapped_column(
|
to_status_id: Mapped[int] = mapped_column(
|
||||||
ForeignKey("statuses.id"),
|
ForeignKey("statuses.id"),
|
||||||
nullable=False,
|
|
||||||
comment="Новый статус",
|
comment="Новый статус",
|
||||||
)
|
)
|
||||||
to_status: Mapped[Status] = relationship(
|
to_status: Mapped[Status] = relationship(
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
from datetime import datetime
|
|
||||||
from typing import Optional, TYPE_CHECKING
|
from typing import Optional, TYPE_CHECKING
|
||||||
|
|
||||||
from sqlalchemy import ForeignKey
|
from sqlalchemy import ForeignKey
|
||||||
@ -16,10 +15,7 @@ class Client(BaseModel, IdMixin, CreatedAtMixin, SoftDeleteMixin):
|
|||||||
|
|
||||||
name: Mapped[str] = mapped_column(unique=True, comment="Название клиента")
|
name: Mapped[str] = mapped_column(unique=True, comment="Название клиента")
|
||||||
|
|
||||||
company_name: Mapped[str] = mapped_column(
|
company_name: Mapped[str] = mapped_column(comment="Название компании")
|
||||||
nullable=False,
|
|
||||||
comment="Название компании",
|
|
||||||
)
|
|
||||||
|
|
||||||
products: Mapped[list["Product"]] = relationship(
|
products: Mapped[list["Product"]] = relationship(
|
||||||
back_populates="client", lazy="noload"
|
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_id: Mapped[int] = mapped_column(ForeignKey("fulfillment_base_products.id"))
|
||||||
product: Mapped["Product"] = relationship(back_populates="images")
|
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)
|
prepared_data = await self._prepare_create(data)
|
||||||
obj = self.entity_class(**prepared_data)
|
obj = self.entity_class(**prepared_data)
|
||||||
self.session.add(obj)
|
self.session.add(obj)
|
||||||
await self.session.flash()
|
await self.session.flush()
|
||||||
await self.session.refresh(obj)
|
await self.session.refresh(obj)
|
||||||
await self._after_create(obj, data)
|
await self._after_create(obj, data)
|
||||||
await self.session.commit()
|
await self.session.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user