Spaces:
Sleeping
Sleeping
Download app/db/models.py from sandy898/resonate-api: direct link, hf CLI and curl.
- Browser
- Download file 2.6 kB
-
https://huggingface.co/spaces/sandy898/resonate-api/resolve/main/app/db/models.py
- Command line
-
hf download hf://spaces/sandy898/resonate-api/app/db/models.py
-
curl -L -o models.py https://huggingface.co/spaces/sandy898/resonate-api/resolve/main/app/db/models.py
2.6 kB
| from sqlalchemy import Column, Integer, String, Float, Boolean, ForeignKey, DateTime, Text, UniqueConstraint | |
| from sqlalchemy.orm import relationship | |
| from sqlalchemy.sql import func | |
| from app.db.database import Base | |
| class User(Base): | |
| __tablename__ = "users" | |
| id = Column(String, primary_key=True, index=True) # UUID string | |
| email = Column(String, unique=True, index=True, nullable=False) | |
| username = Column(String, unique=True, index=True, nullable=False) | |
| hashed_password = Column(String, nullable=False) | |
| reputation_score = Column(Integer, default=0) | |
| created_at = Column(DateTime(timezone=True), server_default=func.now()) | |
| class Interaction(Base): | |
| __tablename__ = "interactions" | |
| id = Column(Integer, primary_key=True, index=True) | |
| user_id = Column(String, ForeignKey("users.id", ondelete="CASCADE"), nullable=False) | |
| item_index = Column(Integer, nullable=False) | |
| rating = Column(Float, nullable=False) | |
| created_at = Column(DateTime(timezone=True), server_default=func.now()) | |
| __table_args__ = (UniqueConstraint('user_id', 'item_index', name='uq_user_item'),) | |
| class List(Base): | |
| __tablename__ = "lists" | |
| id = Column(String, primary_key=True, index=True) # UUID string | |
| user_id = Column(String, ForeignKey("users.id", ondelete="CASCADE"), nullable=False) | |
| title = Column(String, nullable=False) | |
| description = Column(Text, nullable=True) | |
| is_public = Column(Boolean, default=True) | |
| is_official = Column(Boolean, default=False) | |
| upvotes = Column(Integer, default=0) | |
| created_at = Column(DateTime(timezone=True), server_default=func.now()) | |
| user = relationship("User") | |
| items = relationship("ListItem", back_populates="list", cascade="all, delete-orphan") | |
| class ListItem(Base): | |
| __tablename__ = "list_items" | |
| id = Column(Integer, primary_key=True, index=True) | |
| list_id = Column(String, ForeignKey("lists.id", ondelete="CASCADE"), nullable=False) | |
| item_index = Column(Integer, nullable=False) | |
| added_at = Column(DateTime(timezone=True), server_default=func.now()) | |
| list = relationship("List", back_populates="items") | |
| __table_args__ = (UniqueConstraint('list_id', 'item_index', name='uq_list_item'),) | |
| class Comment(Base): | |
| __tablename__ = "comments" | |
| id = Column(String, primary_key=True, index=True) # UUID | |
| user_id = Column(String, ForeignKey("users.id", ondelete="CASCADE"), nullable=False) | |
| item_index = Column(Integer, nullable=False) | |
| content = Column(Text, nullable=False) | |
| created_at = Column(DateTime(timezone=True), server_default=func.now()) | |
| user = relationship("User") | |