33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
from sqlalchemy import Boolean, ForeignKey, Index, Text
|
|
from sqlalchemy.dialects.postgresql import TSVECTOR
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from db.base import Base
|
|
|
|
|
|
class Category(Base):
|
|
__tablename__ = "categories"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
name: Mapped[str] = mapped_column(Text, nullable=False)
|
|
parent_id: Mapped[int | None] = mapped_column(ForeignKey("categories.id"))
|
|
|
|
parent: Mapped["Category"] = relationship("Category", remote_side=[id])
|
|
|
|
|
|
class Product(Base):
|
|
__tablename__ = "products"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
category_id: Mapped[int | None] = mapped_column(ForeignKey("categories.id"))
|
|
name: Mapped[str] = mapped_column(Text, nullable=False)
|
|
description: Mapped[str | None] = mapped_column(Text)
|
|
price: Mapped[int] = mapped_column()
|
|
img_path: Mapped[str] = mapped_column(Text, nullable=True)
|
|
file_id: Mapped[str] = mapped_column(Text, nullable=True, unique=True)
|
|
is_hidden: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
|
|
search_vector: Mapped[str] = mapped_column(TSVECTOR)
|
|
|
|
__table_args__ = (Index("idx_products_search", "search_vector", postgresql_using="gin"),)
|