Spaces:
Runtime error
Runtime error
| from sqlalchemy import Column, String, Integer, ForeignKey | |
| from sqlalchemy.dialects.postgresql import UUID | |
| from sqlalchemy.orm import relationship | |
| from backend.app.models.base import BaseDBModel | |
| class Booking(BaseDBModel): | |
| __tablename__ = "bookings" | |
| code = Column(String, unique=True, index=True, nullable=False) # e.g. B-2401 | |
| job_id = Column(UUID(as_uuid=True), ForeignKey("jobs.id", ondelete="SET NULL"), nullable=True) | |
| customer_id = Column(UUID(as_uuid=True), ForeignKey("users.id", ondelete="CASCADE"), index=True, nullable=False) | |
| worker_id = Column(UUID(as_uuid=True), ForeignKey("users.id", ondelete="CASCADE"), index=True, nullable=False) | |
| amount = Column(Integer, nullable=False) | |
| status = Column(String, nullable=False, default="ACCEPTED", index=True) # ACCEPTED, IN_PROGRESS, COMPLETED, RATED, DISPUTED | |
| # Relationships | |
| job = relationship("Job", back_populates="bookings") | |
| customer = relationship("User", foreign_keys=[customer_id]) | |
| worker = relationship("User", foreign_keys=[worker_id]) | |
| reviews = relationship("Review", back_populates="booking", cascade="all, delete-orphan") | |