From 30e4be9c44f2489b31dbcda1a400f16f074c042a Mon Sep 17 00:00:00 2001 From: chihlasm Date: Wed, 25 Feb 2026 13:26:20 -0500 Subject: [PATCH] feat: add sync columns and source_tree relationship to StepLibrary model Co-Authored-By: Claude Sonnet 4.6 --- backend/app/models/step_library.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/backend/app/models/step_library.py b/backend/app/models/step_library.py index a3f23488..bd2b223e 100644 --- a/backend/app/models/step_library.py +++ b/backend/app/models/step_library.py @@ -13,6 +13,7 @@ if TYPE_CHECKING: from app.models.account import Account from app.models.step_category import StepCategory from app.models.session import Session + from app.models.tree import Tree class StepLibrary(Base): @@ -95,10 +96,26 @@ class StepLibrary(Base): # Soft delete is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True) + # Sync tracking (flow-sourced steps) + source_tree_id: Mapped[Optional[uuid.UUID]] = mapped_column( + UUID(as_uuid=True), + ForeignKey('trees.id', ondelete='SET NULL'), + nullable=True, + index=True + ) + source_node_id: Mapped[Optional[str]] = mapped_column(String(255), nullable=True) + is_flow_synced: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False) + last_synced_at: Mapped[Optional[datetime]] = mapped_column(DateTime(timezone=True), nullable=True) + # Relationships creator: Mapped["User"] = relationship("User", foreign_keys=[created_by]) team: Mapped[Optional["Team"]] = relationship("Team") account: Mapped[Optional["Account"]] = relationship("Account", foreign_keys=[account_id], back_populates="step_library") + source_tree: Mapped[Optional["Tree"]] = relationship( + "Tree", + foreign_keys=[source_tree_id], + lazy="select" + ) category: Mapped[Optional["StepCategory"]] = relationship("StepCategory") ratings: Mapped[list["StepRating"]] = relationship("StepRating", back_populates="step", cascade="all, delete-orphan") usage_logs: Mapped[list["StepUsageLog"]] = relationship("StepUsageLog", back_populates="step", cascade="all, delete-orphan")