Fred808 commited on
Commit
56f4c2b
·
verified ·
1 Parent(s): e472a99

Update app/db/models.py

Browse files
Files changed (1) hide show
  1. app/db/models.py +16 -1
app/db/models.py CHANGED
@@ -66,6 +66,7 @@ class User(Base):
66
  products = relationship("Product", back_populates="seller")
67
  orders = relationship("Order", back_populates="customer")
68
  notifications = relationship("Notification", back_populates="user")
 
69
 
70
  class Product(Base):
71
  __tablename__ = "products"
@@ -168,4 +169,18 @@ class Event(Base):
168
  reminder_sent: Mapped[bool] = mapped_column(Boolean, default=False)
169
 
170
  # Relationship
171
- user = relationship("User")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  products = relationship("Product", back_populates="seller")
67
  orders = relationship("Order", back_populates="customer")
68
  notifications = relationship("Notification", back_populates="user")
69
+ sessions = relationship("Session", back_populates="user", cascade="all, delete-orphan")
70
 
71
  class Product(Base):
72
  __tablename__ = "products"
 
169
  reminder_sent: Mapped[bool] = mapped_column(Boolean, default=False)
170
 
171
  # Relationship
172
+ user = relationship("User")
173
+
174
+ class Session(Base):
175
+ __tablename__ = "sessions"
176
+
177
+ id: Mapped[int] = mapped_column(primary_key=True)
178
+ user_id: Mapped[int] = mapped_column(ForeignKey("users.id"))
179
+ session_token: Mapped[str] = mapped_column(String, unique=True, index=True)
180
+ last_activity: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
181
+ created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
182
+ expires_at: Mapped[datetime] = mapped_column(DateTime)
183
+ is_active: Mapped[bool] = mapped_column(Boolean, default=True)
184
+
185
+ # Relationship
186
+ user = relationship("User", back_populates="sessions")