Skip to content

Commit cd39c65

Browse files
committed
models: add missing foreign key to workflow_uuid of Job
Closes #210
1 parent 0ce3bb8 commit cd39c65

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""Foreign key for workflow_uuid of Job.
2+
3+
Revision ID: ef26a208a3ae
4+
Revises: 126601b69c78
5+
Create Date: 2023-11-24 15:09:49.671968
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
from sqlalchemy.dialects import postgresql
11+
12+
# revision identifiers, used by Alembic.
13+
revision = "ef26a208a3ae"
14+
down_revision = "126601b69c78"
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
"""Upgrade to ef26a208a3ae."""
21+
op.alter_column(
22+
"job",
23+
"workflow_uuid",
24+
existing_type=postgresql.UUID(),
25+
nullable=False,
26+
schema="__reana",
27+
)
28+
op.create_foreign_key(
29+
"_job_workflow_uuid_fk",
30+
"job",
31+
"workflow",
32+
["workflow_uuid"],
33+
["id_"],
34+
source_schema="__reana",
35+
referent_schema="__reana",
36+
)
37+
38+
39+
def downgrade():
40+
"""Downgrade to 126601b69c78."""
41+
op.drop_constraint(
42+
"_job_workflow_uuid_fk", "job", schema="__reana", type_="foreignkey"
43+
)
44+
op.alter_column(
45+
"job",
46+
"workflow_uuid",
47+
existing_type=postgresql.UUID(),
48+
nullable=True,
49+
schema="__reana",
50+
)

reana_db/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,11 @@ class Job(Base, Timestamp):
813813

814814
id_ = Column(UUIDType, primary_key=True, default=generate_uuid)
815815
backend_job_id = Column(String(256))
816-
workflow_uuid = Column(UUIDType)
816+
workflow_uuid = Column(
817+
UUIDType,
818+
ForeignKey("__reana.workflow.id_", name="_job_workflow_uuid_fk"),
819+
nullable=False,
820+
)
817821
status = Column(Enum(JobStatus), default=JobStatus.created)
818822
compute_backend = Column(String(30))
819823
cvmfs_mounts = Column(Text)

0 commit comments

Comments
 (0)