Automated Action 11ef92d44e Fix circular import issue in database models
- Created a dedicated base_class.py file to define the SQLAlchemy Base
- Updated all models to import Base from base_class.py instead of session.py
- Modified migrations/env.py to properly import models and Base
- Fixed circular dependency between models and base classes
2025-06-02 22:08:10 +00:00

20 lines
796 B
Python

from datetime import datetime
from sqlalchemy import Column, Integer, Text, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from app.db.base_class import Base
class Comment(Base):
__tablename__ = "comments"
id = Column(Integer, primary_key=True, index=True)
content = Column(Text, nullable=False)
author_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
post_id = Column(Integer, ForeignKey("posts.id", ondelete="CASCADE"), nullable=False)
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
# Relationships
author = relationship("User", back_populates="comments")
post = relationship("Post", back_populates="comments")