feat: add customer travel records and browse history
This commit is contained in:
1 parent
0139fe6382
commit
6d9a546918
79 files changed
+12362
-112
No files matched your search
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime, timezone
|
||||
from uuid import uuid4
|
||||
from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, String, Text, UniqueConstraint
|
||||
from sqlalchemy import Boolean, DateTime, ForeignKey, Index, Integer, String, Text, UniqueConstraint
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from .database import Base
|
||||
@@ -344,6 +344,44 @@ class Customer(Base):
|
||||
updatedAt: Mapped[datetime] = mapped_column(DateTime, default=utc_now, onupdate=utc_now, nullable=False)
|
||||
|
||||
orders: Mapped[list["Order"]] = relationship(back_populates="customer")
|
||||
browseHistory: Mapped[list["CustomerBrowseHistory"]] = relationship(
|
||||
back_populates="customer",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
|
||||
|
||||
class CustomerBrowseHistory(Base):
|
||||
__tablename__ = "CustomerBrowseHistory"
|
||||
__table_args__ = (
|
||||
UniqueConstraint(
|
||||
"customerId",
|
||||
"itemType",
|
||||
"itemId",
|
||||
name="uq_CustomerBrowseHistory_customer_item",
|
||||
),
|
||||
Index(
|
||||
"ix_CustomerBrowseHistory_customer_visitedAt",
|
||||
"customerId",
|
||||
"visitedAt",
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[str] = mapped_column(String, primary_key=True, default=new_id)
|
||||
customerId: Mapped[str] = mapped_column(
|
||||
String,
|
||||
ForeignKey("Customer.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
itemType: Mapped[str] = mapped_column(String, nullable=False)
|
||||
itemId: Mapped[str] = mapped_column(String, nullable=False)
|
||||
title: Mapped[str] = mapped_column(String, nullable=False)
|
||||
image: Mapped[str] = mapped_column(String, nullable=False, default="")
|
||||
visitedAt: Mapped[datetime] = mapped_column(DateTime, default=utc_now, nullable=False)
|
||||
createdAt: Mapped[datetime] = mapped_column(DateTime, default=utc_now, nullable=False)
|
||||
updatedAt: Mapped[datetime] = mapped_column(DateTime, default=utc_now, onupdate=utc_now, nullable=False)
|
||||
|
||||
customer: Mapped[Customer] = relationship(back_populates="browseHistory")
|
||||
|
||||
|
||||
class Order(Base):
|
||||
|
||||
Reference in new issue
Block a user