Skip to content

Commit

Permalink
Move workspace.db API field to database_name
Browse files Browse the repository at this point in the history
The fact that this attribute lives on `workspace` is an internal Job
Server implementation detail that we don't want to expose in the API it
presents to Job Runner (specifically because we want to change it
shortly).

The corresponding PR in Job Runner, which must be deployed first, is:
 * https://github.com/opensafely-core/job-runner/pull/6509
  • Loading branch information
evansd committed Sep 11, 2023
1 parent 85c05c8 commit 6b80a62
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion jobserver/api/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ class Meta:
"name",
"repo",
"branch",
"db",
"created_by",
"created_at",
]
Expand Down Expand Up @@ -257,6 +256,7 @@ class Meta:
"created_by",
"created_at",
"workspace",
"database_name",
"project",
"orgs",
]
Expand Down
7 changes: 7 additions & 0 deletions jobserver/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,13 @@ def status(self):

return "unknown"

@property
def database_name(self):
# TODO: This is temporary code. We're going to remove the `workspace.db` column
# entirely and use different logic for decided which database a job runs
# against.
return self.workspace.db


class Org(models.Model):
"""An Organisation using the platform"""
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/jobserver/api/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,11 +808,11 @@ def dictify(od):
"project": project.slug,
"requested_actions": ["frob", "wizzle"],
"sha": "",
"database_name": "full",
"workspace": {
"name": workspace.name,
"repo": workspace.repo.url,
"branch": "",
"db": "full",
"created_by": workspace.created_by.username,
"created_at": now_iso,
},
Expand All @@ -828,11 +828,11 @@ def dictify(od):
"project": project.slug,
"requested_actions": ["frobnicate", "wibble"],
"sha": "",
"database_name": "full",
"workspace": {
"name": workspace.name,
"repo": workspace.repo.url,
"branch": "",
"db": "full",
"created_by": workspace.created_by.username,
"created_at": now_iso,
},
Expand All @@ -848,11 +848,11 @@ def dictify(od):
"project": project.slug,
"requested_actions": ["analyse"],
"sha": "",
"database_name": "full",
"workspace": {
"name": workspace.name,
"repo": workspace.repo.url,
"branch": "",
"db": "full",
"created_by": workspace.created_by.username,
"created_at": now_iso,
},
Expand Down

0 comments on commit 6b80a62

Please sign in to comment.