From a2e10c2d799d5a4a0551a2b96df6b76fa1c5df71 Mon Sep 17 00:00:00 2001 From: snnbotchway Date: Mon, 26 Jun 2023 00:11:37 +0000 Subject: [PATCH] Make db config common --- .github/workflows/checks.yml | 2 +- app/.env.dist | 1 + app/storeroom/settings/common.py | 9 +++++++++ app/storeroom/settings/dev.py | 11 ----------- app/storeroom/settings/prod.py | 10 ---------- 5 files changed, 11 insertions(+), 22 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 7fde2f9..8b0cd69 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -26,7 +26,7 @@ jobs: run: cp .env.dist .env working-directory: ./app/ - # TODO: Uncomment after writing some tests + # TODO: Uncomment after writing some tests, since pytest exits with a non-zero code if there are no tests. # - name: Test # run: docker compose run --rm app sh -c pytest # working-directory: ./app/ diff --git a/app/.env.dist b/app/.env.dist index e69de29..d7eaf5a 100644 --- a/app/.env.dist +++ b/app/.env.dist @@ -0,0 +1 @@ +DATABASE_URL=postgres://postgres:change_me@db:5432/devdb diff --git a/app/storeroom/settings/common.py b/app/storeroom/settings/common.py index 7945d57..36889d0 100644 --- a/app/storeroom/settings/common.py +++ b/app/storeroom/settings/common.py @@ -96,6 +96,15 @@ USE_TZ = True +# Parse database connection url strings +# like psql://user:pass@127.0.0.1:8458/db +DATABASES = { + # read os.environ['DATABASE_URL'] and raises + # ImproperlyConfigured exception if not found + "default": env.db(), +} + + # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.2/howto/static-files/ diff --git a/app/storeroom/settings/dev.py b/app/storeroom/settings/dev.py index ccf42f1..d958774 100644 --- a/app/storeroom/settings/dev.py +++ b/app/storeroom/settings/dev.py @@ -5,14 +5,3 @@ SECRET_KEY = "change_me" ALLOWED_HOSTS = ["*"] - -DATABASES = { - "default": { - "ENGINE": "django.db.backends.postgresql", - "NAME": "devdb", - "USER": "postgres", - "PASSWORD": "change_me", - "HOST": "db", - "PORT": "5432", - } -} diff --git a/app/storeroom/settings/prod.py b/app/storeroom/settings/prod.py index f613821..b983b02 100644 --- a/app/storeroom/settings/prod.py +++ b/app/storeroom/settings/prod.py @@ -7,13 +7,3 @@ SECRET_KEY = env("SECRET_KEY") ALLOWED_HOSTS = env("ALLOWED_HOSTS") - -# Parse database connection url strings -# like psql://user:pass@127.0.0.1:8458/db -DATABASES = { - # read os.environ['DATABASE_URL'] and raises - # ImproperlyConfigured exception if not found - # - # The db() method is an alias for db_url(). - "default": env.db(), -}