Skip to content

Instantly share code, notes, and snippets.

@seta-phucpham
Created January 31, 2024 04:04
Show Gist options
  • Save seta-phucpham/af7f17d411e28431992a2406bad08ffc to your computer and use it in GitHub Desktop.
Save seta-phucpham/af7f17d411e28431992a2406bad08ffc to your computer and use it in GitHub Desktop.
Table design

GoalKR

  • Cần có attachment và comment riêng
  • Cần có status (các status nào?)
  • Cần có weight

Câu hỏi

  • Có cần duedate riêng không?
  • Có cần được approved bởi manager?
  • Weight là trọng số nguyên hay %

Draft

class GoalKeyResult(Base):
    __tablename__ = "goal_key_results"

    id = Column(Integer, primary_key=True, index=True)
    content = Column(String, nullable=False)
    weight = Column(Integer, nullable=False)
    status = Column(String, nullable=False, default="not_achieved")
    type = Column(String, nullable=False, default="personal")
    goal_id = Column(Integer, ForeignKey("goals.id", ondelete="CASCADE"))

    due_date = Column(Date, nullable=True)
    deleted_at = Column(DateTime, nullable=True)
    created_at = Column(DateTime, default=datetime.utcnow)
    created_by = Column(UUID(as_uuid=True), ForeignKey("users.id", ondelete="CASCADE"))
    modified_at = Column(
        DateTime,
        default=datetime.utcnow,
        onupdate=datetime.utcnow,
    )
    modified_by = Column(UUID, nullable=False)

    goal = relationship("Goal", foreign_keys=[goal_id])
    attachments: Mapped[List[AttachmentModel]] = relationship(
        "Attachment", back_populates="goal"
    )


class GoalKeyResultComment(Base):
    __tablename__ = "goal_key_result_comments"

    id = Column(Integer, primary_key=True, index=True)
    content = Column(String, nullable=False)
    goal_key_result_id = Column(Integer, ForeignKey("goal_key_results.id", ondelete="CASCADE"))

    deleted_at = Column(DateTime, nullable=True)
    created_at = Column(DateTime, default=datetime.utcnow)
    created_by = Column(UUID(as_uuid=True), ForeignKey("users.id", ondelete="CASCADE"))
    modified_at = Column(
        DateTime,
        default=datetime.utcnow,
        onupdate=datetime.utcnow,
    )
    modified_by = Column(UUID, nullable=False)

    goal_key_result = relationship("GoalKeyResult", foreign_keys=[goal_key_result_id])
    attachments = relationship("Attachment", back_populates="goal_key_result_comment")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment