Skip to content

Commit 2b74919

Browse files
committed
Remove DATABASE where possible
1 parent bf9a861 commit 2b74919

File tree

7 files changed

+24
-19
lines changed

7 files changed

+24
-19
lines changed

Diff for: docs/developing-locally.rst

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

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

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

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/compose:1.29.2
31-
environment:
32-
DATABASE_URL: pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres/$POSTGRES_DB
3331
commands:
3432
- docker-compose -f local.yml build
3533
- docker-compose -f local.yml run --rm django python manage.py migrate

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
@@ -45,8 +45,6 @@ pytest:
4545
- python
4646
services:
4747
- postgres:{{ cookiecutter.postgresql_version }}
48-
variables:
49-
DATABASE_URL: pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres/$POSTGRES_DB
5048
before_script:
5149
- pip install -r requirements/local.txt
5250
script:

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

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

122122
USER django
123123

124-
RUN DATABASE_URL="" \
125-
{%- if cookiecutter.use_celery == "y" %}
124+
RUN {%- if cookiecutter.use_celery == "y" %}
126125
CELERY_BROKER_URL="" \
127126
{%- endif %}
128127
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
python << END
2019
import sys

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)