Spaces:
Sleeping
Sleeping
File size: 2,692 Bytes
ce1e080 5a5f1de ce1e080 5a5f1de c0f9c82 5a5f1de |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
import uuid
from datetime import date, datetime
from enum import Enum
from typing import List, Optional
from sqlalchemy import CheckConstraint, UniqueConstraint
from sqlmodel import Field, Relationship, SQLModel
class AssetStatus(str, Enum):
ACTIVE = "Active"
UNAVAILABLE = "Unavailable"
ON_REQUEST = "On Request"
IN_SERVICE = "In Service"
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)
dob: Optional[date] = None
address: Optional[str] = None
profile_picture: Optional[str] = None
created_at: datetime = Field(default_factory=datetime.now)
asset: List["Assets"] = 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(foreign_key="users.id", nullable=False)
team_id: uuid.UUID = Field(foreign_key="teams.id", nullable=False)
role_id: uuid.UUID = Field(foreign_key="roles.id", 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(foreign_key="users.id", 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"),
CheckConstraint("morning_emotion BETWEEN 1 AND 10 or morning_emotion IS NULL"),
CheckConstraint("evening_emotion BETWEEN 1 AND 10 or evening_emotion IS NULL"),
)
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
user_id: uuid.UUID = Field(foreign_key="users.id", nullable=False)
morning_emotion: Optional[int] = Field(default=None, ge=1, le=10)
evening_emotion: Optional[int] = Field(default=None, ge=1, le=10)
log_date: date = Field(default_factory=date.today)
|