Spaces:
Sleeping
Sleeping
shri-jai commited on
Commit ·
119d5fc
1
Parent(s): 448fbf3
feat: updated emotion tag
Browse files- alembic/versions/d9b4df655a55_updated_emotion_tag.py +45 -0
- src/core/models.py +13 -11
- src/home/schemas.py +1 -1
alembic/versions/d9b4df655a55_updated_emotion_tag.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""updated emotion tag
|
| 2 |
+
|
| 3 |
+
Revision ID: d9b4df655a55
|
| 4 |
+
Revises: fec3872d7eba
|
| 5 |
+
Create Date: 2025-12-04 14:34:22.373838
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
from typing import Sequence, Union
|
| 9 |
+
|
| 10 |
+
from alembic import op
|
| 11 |
+
import sqlalchemy as sa
|
| 12 |
+
import sqlmodel.sql.sqltypes
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
# revision identifiers, used by Alembic.
|
| 16 |
+
revision: str = 'd9b4df655a55'
|
| 17 |
+
down_revision: Union[str, Sequence[str], None] = 'fec3872d7eba'
|
| 18 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 19 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def upgrade() -> None:
|
| 23 |
+
"""Upgrade schema."""
|
| 24 |
+
emotion_enum = sa.Enum(
|
| 25 |
+
'JOYFUL', 'HAPPY', 'CALM', 'NEUTRAL', 'ANXIOUS', 'SAD', 'FRUSTRATED',
|
| 26 |
+
name='emotion_enum'
|
| 27 |
+
)
|
| 28 |
+
emotion_enum.create(op.get_bind(), checkfirst=True)
|
| 29 |
+
# ### commands auto generated by Alembic - please adjust! ###
|
| 30 |
+
op.add_column('emotion_logs', sa.Column('morning_emotion', sa.Enum('JOYFUL', 'HAPPY', 'CALM', 'NEUTRAL', 'ANXIOUS', 'SAD', 'FRUSTRATED', name='emotion_enum'), nullable=True))
|
| 31 |
+
op.add_column('emotion_logs', sa.Column('evening_emotion', sa.Enum('JOYFUL', 'HAPPY', 'CALM', 'NEUTRAL', 'ANXIOUS', 'SAD', 'FRUSTRATED', name='emotion_enum'), nullable=True))
|
| 32 |
+
# ### end Alembic commands ###
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def downgrade() -> None:
|
| 36 |
+
"""Downgrade schema."""
|
| 37 |
+
# ### commands auto generated by Alembic - please adjust! ###
|
| 38 |
+
op.drop_column('emotion_logs', 'evening_emotion')
|
| 39 |
+
op.drop_column('emotion_logs', 'morning_emotion')
|
| 40 |
+
emotion_enum = sa.Enum(
|
| 41 |
+
'JOYFUL', 'HAPPY', 'CALM', 'NEUTRAL', 'ANXIOUS', 'SAD', 'FRUSTRATED',
|
| 42 |
+
name='emotion_enum'
|
| 43 |
+
)
|
| 44 |
+
emotion_enum.drop(op.get_bind(), checkfirst=True)
|
| 45 |
+
# ### end Alembic commands ###
|
src/core/models.py
CHANGED
|
@@ -7,8 +7,9 @@ from typing import List, Optional
|
|
| 7 |
|
| 8 |
|
| 9 |
from sqlalchemy.dialects.postgresql import UUID
|
| 10 |
-
from sqlalchemy import CheckConstraint, UniqueConstraint, ForeignKey
|
| 11 |
from sqlmodel import Field, Relationship, SQLModel
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
class AssetStatus(str, Enum):
|
|
@@ -95,15 +96,15 @@ class Assets(SQLModel, table=True):
|
|
| 95 |
name: str = Field(nullable=False)
|
| 96 |
type: str = Field(nullable=False)
|
| 97 |
status: AssetStatus = Field(default=AssetStatus.UNAVAILABLE)
|
| 98 |
-
user: "Users" = Relationship(
|
| 99 |
|
| 100 |
|
| 101 |
class EmotionLogs(SQLModel, table=True):
|
| 102 |
__tablename__ = "emotion_logs"
|
| 103 |
-
__table_args__ = (
|
| 104 |
-
|
| 105 |
-
)
|
| 106 |
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
|
|
|
|
| 107 |
user_id: uuid.UUID = Field(
|
| 108 |
sa_column=Column(
|
| 109 |
UUID(as_uuid=True),
|
|
@@ -111,12 +112,13 @@ class EmotionLogs(SQLModel, table=True):
|
|
| 111 |
nullable=False,
|
| 112 |
)
|
| 113 |
)
|
|
|
|
| 114 |
morning_emotion: Optional[Emotion] = Field(
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
)
|
| 118 |
evening_emotion: Optional[Emotion] = Field(
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
log_date: date = Field(default_factory=date.today)
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
from sqlalchemy.dialects.postgresql import UUID
|
| 10 |
+
from sqlalchemy import CheckConstraint, UniqueConstraint, ForeignKey
|
| 11 |
from sqlmodel import Field, Relationship, SQLModel
|
| 12 |
+
from sqlalchemy import Enum as SQLEnum
|
| 13 |
|
| 14 |
|
| 15 |
class AssetStatus(str, Enum):
|
|
|
|
| 96 |
name: str = Field(nullable=False)
|
| 97 |
type: str = Field(nullable=False)
|
| 98 |
status: AssetStatus = Field(default=AssetStatus.UNAVAILABLE)
|
| 99 |
+
user: "Users" = Relationship(back_populates="asset")
|
| 100 |
|
| 101 |
|
| 102 |
class EmotionLogs(SQLModel, table=True):
|
| 103 |
__tablename__ = "emotion_logs"
|
| 104 |
+
__table_args__ = (UniqueConstraint("user_id", "log_date"),)
|
| 105 |
+
|
|
|
|
| 106 |
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
|
| 107 |
+
|
| 108 |
user_id: uuid.UUID = Field(
|
| 109 |
sa_column=Column(
|
| 110 |
UUID(as_uuid=True),
|
|
|
|
| 112 |
nullable=False,
|
| 113 |
)
|
| 114 |
)
|
| 115 |
+
|
| 116 |
morning_emotion: Optional[Emotion] = Field(
|
| 117 |
+
sa_column=Column(SQLEnum(Emotion, name="emotion_enum", native_enum=True), nullable=True)
|
| 118 |
+
)
|
|
|
|
| 119 |
evening_emotion: Optional[Emotion] = Field(
|
| 120 |
+
sa_column=Column(SQLEnum(Emotion, name="emotion_enum", native_enum=True), nullable=True)
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
log_date: date = Field(default_factory=date.today)
|
| 124 |
+
|
src/home/schemas.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
from datetime import date
|
| 2 |
from typing import List, Optional
|
| 3 |
from pydantic import BaseModel
|
| 4 |
-
from src.core.
|
| 5 |
|
| 6 |
class EmotionLogCreate(BaseModel):
|
| 7 |
user_id: str
|
|
|
|
| 1 |
from datetime import date
|
| 2 |
from typing import List, Optional
|
| 3 |
from pydantic import BaseModel
|
| 4 |
+
from src.core.models import Emotion
|
| 5 |
|
| 6 |
class EmotionLogCreate(BaseModel):
|
| 7 |
user_id: str
|