yuvabe-dev / src /core /models.py
shri-jai
fix: apk_link added to db
51f598e
from sqlalchemy.dialects.postgresql import ARRAY
from sqlalchemy import Column, String
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 AppVersion(SQLModel, table=True):
__tablename__ = "app_version"
version: str = Field(primary_key=True)
apk_download_link: str
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")
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)
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,
)
)
name: str = Field(nullable=False)
type: str = Field(nullable=False)
status: AssetStatus = Field(default=AssetStatus.UNAVAILABLE)
user: "Users" = Relationship(back_populates="asset")
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)