🐛 fix(flows.py): add missing import statement for TYPE_CHECKING ✨ feat(flows.py): add user_id field to FlowCreate model to allow specifying the user for a new flow ✨ feat(flows.py): add user_id field to FlowRead model to include the user_id in the response ✨ feat(flows.py): add user_id field to Flow model and create a relationship with User model ✨ feat(flows.py): add current_user dependency to create_flow endpoint to set the user_id for a new flow ✨ feat(flows.py): add current_user dependency to read_flows endpoint to filter flows by current user ✨ feat(flows.py): add current_user dependency to read_flow endpoint to filter flow by current user ✨ feat(flows.py): add current_user dependency to update_flow endpoint to filter flow by current user ✨ feat(flows.py): add current_user dependency to delete_flow endpoint to filter flow by current user ✨ feat(flows.py): add current_user dependency to create_flows endpoint to set the user_id for new flows ✨ feat(flows.py): add current_user dependency to upload_file endpoint to set the user_id for new flows ✨ feat(flows.py): add current_user dependency to download_file endpoint to filter flows by current user 🐛 fix(flow.py): add missing import statement for User model ✨ feat(flow.py): add user_id field to Flow model to associate a flow with a user
53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
# Path: src/backend/langflow/database/models/flow.py
|
|
|
|
from langflow.services.database.models.base import SQLModelSerializable
|
|
from pydantic import validator
|
|
from sqlmodel import Field, JSON, Column, Relationship
|
|
from uuid import UUID, uuid4
|
|
from typing import Dict, Optional, TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from langflow.services.database.models.user import User
|
|
|
|
|
|
class FlowBase(SQLModelSerializable):
|
|
name: str = Field(index=True)
|
|
description: Optional[str] = Field(index=True)
|
|
data: Optional[Dict] = Field(default=None)
|
|
|
|
@validator("data")
|
|
def validate_json(v):
|
|
if not v:
|
|
return v
|
|
if not isinstance(v, dict):
|
|
raise ValueError("Flow must be a valid JSON")
|
|
|
|
# data must contain nodes and edges
|
|
if "nodes" not in v.keys():
|
|
raise ValueError("Flow must have nodes")
|
|
if "edges" not in v.keys():
|
|
raise ValueError("Flow must have edges")
|
|
|
|
return v
|
|
|
|
|
|
class Flow(FlowBase, table=True):
|
|
id: UUID = Field(default_factory=uuid4, primary_key=True, unique=True)
|
|
data: Optional[Dict] = Field(default=None, sa_column=Column(JSON))
|
|
user_id: UUID = Field(index=True, foreign_key="user.id")
|
|
user: "User" = Relationship(back_populates="flows")
|
|
|
|
|
|
class FlowCreate(FlowBase):
|
|
user_id: Optional[UUID] = None
|
|
|
|
|
|
class FlowRead(FlowBase):
|
|
id: UUID
|
|
user_id: UUID = Field()
|
|
|
|
|
|
class FlowUpdate(SQLModelSerializable):
|
|
name: Optional[str] = None
|
|
description: Optional[str] = None
|
|
data: Optional[Dict] = None
|