Skip to content

Commit 22e2177

Browse files
committed
Remove DATABASE_URL
1 parent 14cca33 commit 22e2177

5 files changed

Lines changed: 17 additions & 10 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
"features": {
2929
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
3030
},
31-
"remoteEnv": {
32-
"DATABASE_URL": "postgres://${containerEnv:POSTGRES_USER}:${containerEnv:POSTGRES_PASSWORD}@${containerEnv:POSTGRES_HOST}:${containerEnv:POSTGRES_PORT}/${containerEnv:POSTGRES_DB}"
33-
},
3431
// Set *default* container specific settings.json values on container create.
3532
"customizations": {
3633
"vscode": {

CONTRIBUTING.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ Running Tests Locally
156156
The easiest way to run tests is by running ``just test``. This will run the tests from
157157
the ``django`` Docker service so they have access to Postgres. To run the tests in the
158158
local environment, for example using the VSCode test runner, you must have PostgreSQL_
159-
installed on your computer. Django should automatically create a test database for you
160-
when you run the tests.
159+
installed on your computer, and you must set the environment variable
160+
``DATABASE_URL=postgres:///democrasite``. Django should automatically create a test
161+
database for you when you run the tests.
161162

162163
.. _PostgreSQL: https://www.postgresql.org/download/

compose/production/django/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ RUN chown -R django:django ${APP_HOME}
8888

8989
USER django
9090

91-
RUN DATABASE_URL="" \
92-
REDIS_URL="" \
93-
DJANGO_SETTINGS_MODULE="config.settings.test" \
91+
RUN DJANGO_SETTINGS_MODULE="config.settings.test" \
9492
python manage.py compilemessages
9593

9694
ENTRYPOINT ["/entrypoint"]

compose/production/django/entrypoint

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ if [ -z "${POSTGRES_USER}" ]; then
1010
base_postgres_image_default_user='postgres'
1111
export POSTGRES_USER="${base_postgres_image_default_user}"
1212
fi
13-
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
1413

1514
python << END
1615
import sys

config/settings/base.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,19 @@
3737
# DATABASES
3838
# ------------------------------------------------------------------------------
3939
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
40-
DATABASES = {"default": env.db("DATABASE_URL", default="postgres:///democrasite")}
40+
if db_url := env.db("DATABASE_URL", default=None):
41+
DATABASES = {"default": db_url}
42+
else:
43+
DATABASES = {
44+
"default": {
45+
"ENGINE": "django.db.backends.postgresql",
46+
"NAME": env.str("POSTGRES_DB"),
47+
"USER": env.str("POSTGRES_USER"),
48+
"PASSWORD": env.str("POSTGRES_PASSWORD"),
49+
"HOST": env.str("POSTGRES_HOST", default="postgres"),
50+
"PORT": env.str("POSTGRES_PORT", default="5432"),
51+
},
52+
}
4153
DATABASES["default"]["ATOMIC_REQUESTS"] = True
4254
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
4355
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

0 commit comments

Comments
 (0)