from datetime import datetime from sqlalchemy import Column, Date, DateTime, Float, ForeignKey, Integer, String from sqlalchemy.orm import declarative_base, relationship Base = declarative_base() class Project(Base): __tablename__ = "projects" id = Column(Integer, primary_key=True, index=True) name = Column(String(200), unique=True, nullable=False, index=True) description = Column(String(1000), nullable=True) created_at = Column(DateTime, default=datetime.utcnow, nullable=False) work_logs = relationship( "WorkLogEntry", back_populates="project", cascade="all, delete-orphan", passive_deletes=True, ) class WorkLogEntry(Base): __tablename__ = "work_logs" id = Column(Integer, primary_key=True, index=True) project_id = Column( Integer, ForeignKey("projects.id", ondelete="CASCADE"), nullable=False, index=True, ) date = Column(Date, nullable=False, index=True) hours = Column(Float, nullable=False) description = Column(String(2000), nullable=False) created_at = Column(DateTime, default=datetime.utcnow, nullable=False) project = relationship("Project", back_populates="work_logs")