From 69b73dc49eadb832c3da7c24377a8f2589d4540e Mon Sep 17 00:00:00 2001 From: Audrius Mecionis Date: Thu, 8 Oct 2020 17:55:56 +0200 Subject: [PATCH] models: improve IneractiveSession model --- reana_db/models.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/reana_db/models.py b/reana_db/models.py index d51d8ce..67dfed0 100644 --- a/reana_db/models.py +++ b/reana_db/models.py @@ -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 "".format( - self.user_id, self.session_id, self.workflow_id - ) + """Workflow Session string representation.""" + return "".format(self.session_id, self.workflow_id) class InteractiveSessionType(enum.Enum): @@ -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), @@ -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"