Skip to content

Commit d275ac2

Browse files
committed
Remove DATABASE where possible
1 parent 62f39cd commit d275ac2

File tree

7 files changed

+24
-19
lines changed

7 files changed

+24
-19
lines changed

Diff for: docs/2-local-development/developing-locally.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ First things first.
5454

5555
#. Set the environment variables for your database(s): ::
5656

57-
$ export DATABASE_URL=postgres://postgres:<password>@127.0.0.1:5432/<DB name given to createdb>
57+
$ export POSTGRES_USER=
58+
$ export POSTGRES_PASSWORD=
59+
$ export POSTGRES_DB=<DB name given to createdb>
5860
# Optional: set broker URL if using Celery
5961
$ export CELERY_BROKER_URL=redis://localhost:6379/0
6062

Diff for: {{cookiecutter.project_slug}}/.drone.yml

-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ steps:
2828
pull: if-not-exists
2929
{%- if cookiecutter.use_docker == 'y' %}
3030
image: docker:25.0
31-
environment:
32-
DATABASE_URL: pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres/$POSTGRES_DB
3331
commands:
3432
- docker-compose -f docker-compose.local.yml build
3533
- docker-compose -f docker-compose.docs.yml build

Diff for: {{cookiecutter.project_slug}}/.github/workflows/ci.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ jobs:
6060
CELERY_BROKER_URL: 'redis://localhost:6379/0'
6161
{%- endif %}
6262
# postgres://user:password@host:port/database
63-
DATABASE_URL: 'postgres://postgres:postgres@localhost:5432/postgres'
63+
POSTGRES_USER: 'postgres'
64+
POSTGRES_PASSWORD: 'postgres'
65+
POSTGRES_DB: 'postgres'
66+
POSTGRES_HOST: 'postgres'
67+
6468
{%- endif %}
6569

6670
steps:

Diff for: {{cookiecutter.project_slug}}/.gitlab-ci.yml

-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ pytest:
4242
image: python:3.12
4343
services:
4444
- postgres:{{ cookiecutter.postgresql_version }}
45-
variables:
46-
DATABASE_URL: pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres/$POSTGRES_DB
4745
before_script:
4846
- pip install -r requirements/local.txt
4947
script:

Diff for: {{cookiecutter.project_slug}}/compose/production/django/Dockerfile

+1-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ RUN chown -R django:django ${APP_HOME}
124124

125125
USER django
126126

127-
RUN DATABASE_URL="" \
128-
{%- if cookiecutter.use_celery == "y" %}
127+
RUN {%- if cookiecutter.use_celery == "y" %}
129128
CELERY_BROKER_URL="" \
130129
{%- endif %}
131130
DJANGO_SETTINGS_MODULE="config.settings.test" \

Diff for: {{cookiecutter.project_slug}}/compose/production/django/entrypoint

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ if [ -z "${POSTGRES_USER}" ]; then
1414
base_postgres_image_default_user='postgres'
1515
export POSTGRES_USER="${base_postgres_image_default_user}"
1616
fi
17-
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
1817

1918
wait-for-it "${POSTGRES_HOST}:${POSTGRES_PORT}" -t 30
2019

Diff for: {{cookiecutter.project_slug}}/config/settings/base.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,21 @@
4545
# DATABASES
4646
# ------------------------------------------------------------------------------
4747
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
48-
{% if cookiecutter.use_docker == "y" -%}
49-
DATABASES = {"default": env.db("DATABASE_URL")}
50-
{%- else %}
51-
DATABASES = {
52-
"default": env.db(
53-
"DATABASE_URL",
54-
default="postgres://{% if cookiecutter.windows == 'y' %}localhost{% endif %}/{{cookiecutter.project_slug}}",
55-
),
56-
}
57-
{%- endif %}
48+
49+
if db_url := env.db("DATABASE_URL", default=None):
50+
DATABASES = {"default": db_url}
51+
else:
52+
DATABASES = {
53+
"default": {
54+
"ENGINE": "django.db.backends.postgresql",
55+
"NAME": env.str("POSTGRES_DB"),
56+
"USER": env.str("POSTGRES_USER"),
57+
"PASSWORD": env.str("POSTGRES_PASSWORD"),
58+
"HOST": env.str("POSTGRES_HOST", default="{% if cookiecutter.windows == 'y' or cookiecutter.use_docker == 'n' %}localhost{%else%}postgres{% endif %}"),
59+
"PORT": env.str("POSTGRES_PORT", default="5432"),
60+
},
61+
}
62+
5863
DATABASES["default"]["ATOMIC_REQUESTS"] = True
5964
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
6065
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

0 commit comments

Comments
 (0)