1- from sqlalchemy import Column , Integer , String , ARRAY , Enum , ForeignKey
1+ from sqlalchemy import Column , Integer , String , ARRAY , Enum , ForeignKey , DateTime
22from sqlalchemy .orm import relationship
33from src .database import Base
44from src .models .enums import DayOfWeekEnum
55from src .models .friends import Friendship
6+ import sqlalchemy as sa
67
78class User (Base ):
89 """
@@ -14,10 +15,12 @@ class User(Base):
1415 - `giveaways` (nullable) The list of giveaways a user is entered into.
1516 - `net_id` The user's Net ID.
1617 - `name` The user's name.
17- - `workout_goal` The days of the week the user has set as their personal goal.
18+ - `workout_goal` The number of days the user has set as their personal goal.
1819 - `active_streak` The number of consecutive weeks the user has met their personal goal.
1920 - `max_streak` The maximum number of consecutive weeks the user has met their personal goal.
2021 - `workout_goal` The max number of weeks the user has met their personal goal.
22+ - `last_goal_change` The date and time the user last changed their personal goal.
23+ - `last_streak` The number of consecutive weeks the user has met their personal goal before the last goal change.
2124 - `encoded_image` The profile picture URL of the user.
2225 """
2326
@@ -28,11 +31,15 @@ class User(Base):
2831 giveaways = relationship ("Giveaway" , secondary = "giveaway_instance" , back_populates = "users" )
2932 net_id = Column (String , nullable = False )
3033 name = Column (String , nullable = False )
31- active_streak = Column (Integer , nullable = True )
32- max_streak = Column (Integer , nullable = True )
33- workout_goal = Column (ARRAY (Enum (DayOfWeekEnum )), nullable = True )
34+ active_streak = Column (Integer , nullable = False , default = 0 , server_default = sa .text ('0' ))
35+ max_streak = Column (Integer , nullable = False , default = 0 , server_default = sa .text ('0' ))
36+ workout_goal = Column (Integer , nullable = True )
37+ last_goal_change = Column (DateTime , nullable = True )
38+ last_streak = Column (Integer , nullable = False , default = 0 , server_default = sa .text ('0' ))
3439 encoded_image = Column (String , nullable = True )
3540
41+ goal_history = relationship ("UserWorkoutGoalHistory" , back_populates = "user" , cascade = "all, delete-orphan" , order_by = "UserWorkoutGoalHistory.effective_at.desc()" )
42+
3643 friend_requests_sent = relationship ("Friendship" ,
3744 foreign_keys = "Friendship.user_id" ,
3845 back_populates = "user" )
0 commit comments