| from __future__ import annotations |
|
|
| import uuid |
| from datetime import datetime |
|
|
| from sqlalchemy import ( |
| DateTime, |
| ForeignKey, |
| Text, |
| func, |
| ) |
| from sqlalchemy.dialects.postgresql import JSONB, UUID |
| from sqlalchemy.orm import Mapped, mapped_column, relationship |
|
|
| from app.database.database import Base |
|
|
|
|
| class Commit(Base): |
| """ |
| Represents an approved change committed to the |
| Knowledge Register. |
| |
| Every commit forms part of the audit trail and |
| provides a complete history of how the Knowledge |
| Register evolved over time. |
| """ |
|
|
| __tablename__ = "commits" |
|
|
| id: Mapped[uuid.UUID] = mapped_column( |
| UUID(as_uuid=True), |
| primary_key=True, |
| default=uuid.uuid4, |
| ) |
|
|
| workspace_id: Mapped[uuid.UUID] = mapped_column( |
| UUID(as_uuid=True), |
| ForeignKey("workspaces.id", ondelete="CASCADE"), |
| nullable=False, |
| index=True, |
| ) |
|
|
| proposal_id: Mapped[uuid.UUID] = mapped_column( |
| UUID(as_uuid=True), |
| ForeignKey("proposals.id", ondelete="SET NULL"), |
| nullable=True, |
| index=True, |
| ) |
|
|
| committed_by: Mapped[uuid.UUID] = mapped_column( |
| UUID(as_uuid=True), |
| ForeignKey("users.id", ondelete="RESTRICT"), |
| nullable=False, |
| index=True, |
| ) |
|
|
| message: Mapped[str] = mapped_column( |
| Text, |
| nullable=False, |
| ) |
|
|
| changes: Mapped[dict] = mapped_column( |
| JSONB, |
| nullable=False, |
| ) |
|
|
| committed_at: Mapped[datetime] = mapped_column( |
| DateTime(timezone=True), |
| nullable=False, |
| server_default=func.now(), |
| ) |
|
|
| |
| |
| |
|
|
| workspace: Mapped["Workspace"] = relationship( |
| back_populates="commits", |
| ) |
|
|
| proposal: Mapped["Proposal | None"] = relationship() |
|
|
| author: Mapped["User"] = relationship() |
|
|
| def __repr__(self) -> str: |
| return ( |
| f"<Commit(" |
| f"id={self.id}, " |
| f"committed_at={self.committed_at})>" |
| ) |