diff --git a/backend/add_parent_id_column.py b/backend/add_parent_id_column.py new file mode 100644 index 0000000..4f244ff --- /dev/null +++ b/backend/add_parent_id_column.py @@ -0,0 +1,15 @@ +from sqlmodel import Session, create_engine, text +from database import DATABASE_URL + +def add_column(): + engine = create_engine(DATABASE_URL) + with Session(engine) as session: + try: + session.exec(text("ALTER TABLE comment ADD COLUMN parent_id INTEGER REFERENCES comment(id)")) + session.commit() + print("Successfully added parent_id column to comment table") + except Exception as e: + print(f"Error adding column (might already exist): {e}") + +if __name__ == "__main__": + add_column() diff --git a/backend/models.py b/backend/models.py index f7a3781..58391b5 100644 --- a/backend/models.py +++ b/backend/models.py @@ -138,6 +138,7 @@ class Comment(SQLModel, table=True): show_id: Optional[int] = Field(default=None, foreign_key="show.id") venue_id: Optional[int] = Field(default=None, foreign_key="venue.id") song_id: Optional[int] = Field(default=None, foreign_key="song.id") + parent_id: Optional[int] = Field(default=None, foreign_key="comment.id") user: "User" = Relationship(back_populates="comments") diff --git a/backend/routers/social.py b/backend/routers/social.py index 955e37f..fef693e 100644 --- a/backend/routers/social.py +++ b/backend/routers/social.py @@ -24,8 +24,18 @@ def create_comment( session.commit() session.refresh(db_comment) - # Notify parent author if reply (TODO: Add parent_id to Comment model) - # For now, let's just log it or skip. + # Notify parent author if reply + if db_comment.parent_id: + parent_comment = session.get(Comment, db_comment.parent_id) + if parent_comment and parent_comment.user_id != current_user.id: + create_notification( + session, + user_id=parent_comment.user_id, + title="New Reply", + message=f"Someone replied to your comment.", + type="reply", + link=f"/activity" + ) # Handle Mentions mention_pattern = r"@(\w+)" diff --git a/backend/schemas.py b/backend/schemas.py index aefb2f2..29f790f 100644 --- a/backend/schemas.py +++ b/backend/schemas.py @@ -207,6 +207,7 @@ class CommentBase(SQLModel): show_id: Optional[int] = None venue_id: Optional[int] = None song_id: Optional[int] = None + parent_id: Optional[int] = None class CommentCreate(CommentBase): pass