shri-jai
feat: foodcount
f1cda74
from sqlalchemy.dialects.postgresql import ARRAY
from sqlalchemy import Column, String, text
import uuid
from datetime import date, datetime
from enum import Enum
from typing import List, Optional
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy import CheckConstraint, UniqueConstraint, ForeignKey
from sqlmodel import Field, Relationship, SQLModel
from sqlalchemy import Enum as SQLEnum
class AssetStatus(str, Enum):
ACTIVE = "Active"
UNAVAILABLE = "Unavailable"
ON_REQUEST = "On Request"
IN_SERVICE = "In Service"
class Emotion(str, Enum):
JOYFUL = "joyful"
HAPPY = "happy"
CALM = "calm"
NEUTRAL = "neutral"
ANXIOUS = "anxious"
SAD = "sad"
FRUSTRATED = "frustrated"
class LunchLocation(str, Enum):
SARACON_CAMPUS = "Saracon Campus"
SOLAR_KITCHEN = "Solar Kitchen"
class AppVersion(SQLModel, table=True):
__tablename__ = "app_version"
version: str = Field(primary_key=True)
apk_download_link: str = Field(nullable=False)
ios_download_link: str = Field(nullable=False)
class Users(SQLModel, table=True):
__tablename__ = "users"
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
email_id: str = Field(unique=True, nullable=False)
password: str = Field(nullable=False)
user_name: str = Field(nullable=False)
is_verified: bool = Field(
default=False, sa_column_kwargs={"server_default": "false"}
)
dob: Optional[date] = None
address: Optional[str] = None
profile_picture: Optional[str] = None
join_date: Optional[str] = None
created_at: datetime = Field(default_factory=datetime.now)
asset: List["Assets"] = Relationship(back_populates="user")
water_logs: List["WaterLogs"] = Relationship(back_populates="user")
journal_entries: List["JournalEntry"] = Relationship(back_populates="user")
lunch_preference: LunchLocation = Field(default= None,sa_column_kwargs={"server_default": "SOLAR_KITCHEN"})
class Teams(SQLModel, table=True):
__tablename__ = "teams"
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
name: str = Field(unique=True, nullable=False)
class Roles(SQLModel, table=True):
__tablename__ = "roles"
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True, sa_column_kwargs={"server_default": text("gen_random_uuid()")})
name: str = Field(unique=True, nullable=False)
class UserTeamsRole(SQLModel, table=True):
__tablename__ = "user_teams_role"
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
user_id: uuid.UUID = Field(
sa_column=Column(
UUID(as_uuid=True),
ForeignKey("users.id", ondelete="CASCADE"),
nullable=False,
)
)
team_id: uuid.UUID = Field(
sa_column=Column(
UUID(as_uuid=True),
ForeignKey("teams.id", ondelete="CASCADE"),
nullable=False,
)
)
role_id: uuid.UUID = Field(
sa_column=Column(
UUID(as_uuid=True),
ForeignKey("roles.id", ondelete="CASCADE"),
nullable=False,
)
)
class Assets(SQLModel, table=True):
__tablename__ = "assets"
id: uuid.UUID = Field(
default_factory=uuid.uuid4,
primary_key=True,
)
user_id: uuid.UUID = Field(
sa_column=Column(
UUID(as_uuid=True),
ForeignKey("users.id", ondelete="CASCADE"),
nullable=False,
)
)
asset_id: str = Field(sa_column=Column("asset_id", String, nullable=False))
type: str = Field(nullable=False)
status: AssetStatus = Field(default=AssetStatus.UNAVAILABLE)
user: "Users" = Relationship(back_populates="asset")
__table_args__ = (UniqueConstraint("asset_id", "type", name="unique_assetid_type"),)
class EmotionLogs(SQLModel, table=True):
__tablename__ = "emotion_logs"
__table_args__ = (UniqueConstraint("user_id", "log_date"),)
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
user_id: uuid.UUID = Field(
sa_column=Column(
UUID(as_uuid=True),
ForeignKey("users.id", ondelete="CASCADE"),
nullable=False,
)
)
morning_emotion: Optional[Emotion] = Field(
sa_column=Column(
SQLEnum(Emotion, name="emotion_enum", native_enum=True), nullable=True
)
)
evening_emotion: Optional[Emotion] = Field(
sa_column=Column(
SQLEnum(Emotion, name="emotion_enum", native_enum=True), nullable=True
)
)
log_date: date = Field(default_factory=date.today)