diff --git a/models/deal.py b/models/deal.py index 02568f6..6e3258c 100644 --- a/models/deal.py +++ b/models/deal.py @@ -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", diff --git a/models/mixins.py b/models/mixins.py index 6e434a3..e87006b 100644 --- a/models/mixins.py +++ b/models/mixins.py @@ -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, ) diff --git a/models/project.py b/models/project.py index 142da56..708062d 100644 --- a/models/project.py +++ b/models/project.py @@ -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", diff --git a/models/status.py b/models/status.py index 70b5f70..a57ac5d 100644 --- a/models/status.py +++ b/models/status.py @@ -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( diff --git a/modules/clients/models/client.py b/modules/clients/models/client.py index 032b0ef..4cc936c 100644 --- a/modules/clients/models/client.py +++ b/modules/clients/models/client.py @@ -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" diff --git a/modules/fulfillment_base/models/product.py b/modules/fulfillment_base/models/product.py index eb4fa8a..9d37c9b 100644 --- a/modules/fulfillment_base/models/product.py +++ b/modules/fulfillment_base/models/product.py @@ -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() diff --git a/repositories/mixins.py b/repositories/mixins.py index 659e66e..d748fa2 100644 --- a/repositories/mixins.py +++ b/repositories/mixins.py @@ -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()