Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove old database names and add new ones #653

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")