Skip to content

Commit

Permalink
models: improve IneractiveSession model
Browse files Browse the repository at this point in the history
  • Loading branch information
audrium committed Oct 8, 2020
1 parent 57ec2fa commit 69b73dc
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions reana_db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,23 +286,20 @@ class JobStatus(enum.Enum):
queued = 5


class UserWorkflowSession(Base, Timestamp):
"""User Workflow Session table."""
class WorkflowSession(Base):
"""Workflow Session table."""

__tablename__ = "user_workflow_session"
__tablename__ = "workflow_session"
__table_args__ = {"schema": "__reana"}

user_id = Column(UUIDType, ForeignKey("__reana.user_.id_"), nullable=False)
workflow_id = Column(UUIDType, ForeignKey("__reana.workflow.id_"), nullable=True)
session_id = Column(
UUIDType, ForeignKey("__reana.interactive_session.id_"), primary_key=True
)

def __repr__(self):
"""User Workflow Session string representation."""
return "<UserWorkflowSession {} {} {}>".format(
self.user_id, self.session_id, self.workflow_id
)
"""Workflow Session string representation."""
return "<WorkflowSession {} {}>".format(self.session_id, self.workflow_id)


class InteractiveSessionType(enum.Enum):
Expand All @@ -318,9 +315,7 @@ class InteractiveSession(Base, Timestamp):
id_ = Column(UUIDType, primary_key=True, unique=True, default=generate_uuid)
name = Column(String(255))
path = Column(Text) # path to access the interactive session
status = Column(
Enum(RunStatus), nullable=False, default=RunStatus.created
)
status = Column(Enum(RunStatus), nullable=False, default=RunStatus.created)
owner_id = Column(UUIDType, ForeignKey("__reana.user_.id_"))
type_ = Column(
Enum(InteractiveSessionType),
Expand Down Expand Up @@ -369,6 +364,14 @@ class Workflow(Base, Timestamp):
git_repo = Column(String(255))
git_provider = Column(String(255))

sessions = relationship(
"InteractiveSession",
secondary="__reana.workflow_session",
lazy="dynamic",
backref="workflow",
cascade="all, delete",
)

__table_args__ = (
UniqueConstraint(
"name", "owner_id", "run_number", name="_user_workflow_run_uc"
Expand Down

0 comments on commit 69b73dc

Please sign in to comment.