Skip to content

Commit

Permalink
models: add missing foreign key to workflow_uuid of Job
Browse files Browse the repository at this point in the history
Closes #210
  • Loading branch information
mdonadoni committed Nov 24, 2023
1 parent 0ce3bb8 commit cd39c65
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""Foreign key for workflow_uuid of Job.
Revision ID: ef26a208a3ae
Revises: 126601b69c78
Create Date: 2023-11-24 15:09:49.671968
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "ef26a208a3ae"
down_revision = "126601b69c78"
branch_labels = None
depends_on = None


def upgrade():
"""Upgrade to ef26a208a3ae."""
op.alter_column(
"job",
"workflow_uuid",
existing_type=postgresql.UUID(),
nullable=False,
schema="__reana",
)
op.create_foreign_key(
"_job_workflow_uuid_fk",
"job",
"workflow",
["workflow_uuid"],
["id_"],
source_schema="__reana",
referent_schema="__reana",
)


def downgrade():
"""Downgrade to 126601b69c78."""
op.drop_constraint(
"_job_workflow_uuid_fk", "job", schema="__reana", type_="foreignkey"
)
op.alter_column(
"job",
"workflow_uuid",
existing_type=postgresql.UUID(),
nullable=True,
schema="__reana",
)
6 changes: 5 additions & 1 deletion reana_db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,11 @@ class Job(Base, Timestamp):

id_ = Column(UUIDType, primary_key=True, default=generate_uuid)
backend_job_id = Column(String(256))
workflow_uuid = Column(UUIDType)
workflow_uuid = Column(
UUIDType,
ForeignKey("__reana.workflow.id_", name="_job_workflow_uuid_fk"),
nullable=False,
)
status = Column(Enum(JobStatus), default=JobStatus.created)
compute_backend = Column(String(30))
cvmfs_mounts = Column(Text)
Expand Down

0 comments on commit cd39c65

Please sign in to comment.