Files
AICyclingCoach/backend/app/models/plan.py
2025-09-12 09:08:10 -07:00

15 lines
773 B
Python

from sqlalchemy import Column, Integer, ForeignKey, JSON
from sqlalchemy.orm import relationship
from .base import BaseModel
class Plan(BaseModel):
__tablename__ = "plans"
jsonb_plan = Column(JSON, nullable=False) # Changed from JSONB to JSON for SQLite compatibility
version = Column(Integer, nullable=False)
parent_plan_id = Column(Integer, ForeignKey('plans.id'), nullable=True)
parent_plan = relationship("Plan", remote_side="Plan.id", backref="child_plans")
analyses = relationship("Analysis", back_populates="plan", lazy="selectin")
workouts = relationship("Workout", back_populates="plan", cascade="all, delete-orphan", lazy="selectin")
rules = relationship("Rule", secondary="plan_rules", back_populates="plans", lazy="selectin")