Skip to content

Commit

Permalink
Merge pull request #653 from opensafely-core/evansd/db-config
Browse files Browse the repository at this point in the history
Remove old database names and add new ones
  • Loading branch information
evansd authored Sep 13, 2023
2 parents 1a61a70 + 6bf3f43 commit 89b2f61
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
11 changes: 1 addition & 10 deletions dotenv-sample
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,7 @@ MEDIUM_PRIVACY_STORAGE_BASE=/workdir/workspaces
# A Github developer token that has read access to private repos
PRIVATE_REPO_ACCESS_TOKEN=

# A database containing dummy data; results from this could be freely
# published without review
DUMMY_DATABASE_URL=mssql+pyodbc://xxxx

# A database containing a slice of the full data; useful for checking
# or debuggin real data without potentially having to wait for hours
# for completion
SLICE_DATABASE_URL=mssql+pyodbc://xxxx

# The full database
# The DSN for accessing the database
FULL_DATABASE_URL=mssql+pyodbc://xxxx

# Database in which we can create temporary tables
Expand Down
10 changes: 7 additions & 3 deletions jobrunner/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@ def _is_valid_backend_name(name):

DOCKER_REGISTRY = os.environ.get("DOCKER_REGISTRY", "ghcr.io/opensafely-core")

db_names = ["full", "default", "include_t1oo"]
DATABASE_URLS = {
"full": os.environ.get("FULL_DATABASE_URL"),
"slice": os.environ.get("SLICE_DATABASE_URL"),
"dummy": os.environ.get("DUMMY_DATABASE_URL"),
db_name: db_url
for db_name, db_url in [
(db_name, os.environ.get("{db_name.upper()}_DATABASE_URL"))
for db_name in db_names
]
if db_url
}

TEMP_DATABASE_NAME = os.environ.get("TEMP_DATABASE_NAME")
Expand Down
11 changes: 8 additions & 3 deletions tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def add_maintenance_command(mock_subprocess_run, current):
)


def test_maintenance_mode_off(mock_subprocess_run, db):
def test_maintenance_mode_off(mock_subprocess_run, db, db_config):
ps = add_maintenance_command(mock_subprocess_run, current=None)
ps.stdout = ""
assert service.maintenance_mode() is None
Expand All @@ -70,7 +70,7 @@ def test_maintenance_mode_off(mock_subprocess_run, db):
assert service.maintenance_mode() is None


def test_maintenance_mode_on(mock_subprocess_run, db):
def test_maintenance_mode_on(mock_subprocess_run, db, db_config):
ps = add_maintenance_command(mock_subprocess_run, current=None)
ps.stdout = "db-maintenance"
ps.stderr = "other stuff"
Expand All @@ -83,11 +83,16 @@ def test_maintenance_mode_on(mock_subprocess_run, db):
assert service.maintenance_mode() == "db-maintenance"


def test_maintenance_mode_error(mock_subprocess_run, db):
def test_maintenance_mode_error(mock_subprocess_run, db, db_config):
ps = add_maintenance_command(mock_subprocess_run, current=None)
ps.returncode = 1
ps.stdout = ""
ps.stderr = "error"

with pytest.raises(subprocess.CalledProcessError):
service.maintenance_mode()


@pytest.fixture
def db_config(monkeypatch):
monkeypatch.setitem(config.DATABASE_URLS, "full", "mssql://localhost")

0 comments on commit 89b2f61

Please sign in to comment.