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 DATABASE where possible #4862

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion docs/developing-locally.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ First things first.

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

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

Expand Down
2 changes: 0 additions & 2 deletions {{cookiecutter.project_slug}}/.drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ steps:
pull: if-not-exists
{%- if cookiecutter.use_docker == 'y' %}
image: docker/compose:1.29.2
environment:
DATABASE_URL: pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres/$POSTGRES_DB
commands:
- docker-compose -f local.yml build
- docker-compose -f local.yml run --rm django python manage.py migrate
Expand Down
6 changes: 5 additions & 1 deletion {{cookiecutter.project_slug}}/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ jobs:
CELERY_BROKER_URL: 'redis://localhost:6379/0'
{%- endif %}
# postgres://user:password@host:port/database
DATABASE_URL: 'postgres://postgres:postgres@localhost:5432/postgres'
POSTGRES_USER: 'postgres'
POSTGRES_PASSWORD: 'postgres'
POSTGRES_DB: 'postgres'
POSTGRES_HOST: 'postgres'

{%- endif %}

steps:
Expand Down
2 changes: 0 additions & 2 deletions {{cookiecutter.project_slug}}/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ pytest:
- python
services:
- postgres:{{ cookiecutter.postgresql_version }}
variables:
DATABASE_URL: pgsql://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres/$POSTGRES_DB
before_script:
- pip install -r requirements/local.txt
script:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ RUN chown django:django ${APP_HOME}

USER django

RUN DATABASE_URL="" \
{%- if cookiecutter.use_celery == "y" %}
RUN {%- if cookiecutter.use_celery == "y" %}
CELERY_BROKER_URL="" \
{%- endif %}
DJANGO_SETTINGS_MODULE="config.settings.test" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ if [ -z "${POSTGRES_USER}" ]; then
base_postgres_image_default_user='postgres'
export POSTGRES_USER="${base_postgres_image_default_user}"
fi
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"

python << END
import sys
Expand Down
25 changes: 15 additions & 10 deletions {{cookiecutter.project_slug}}/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,21 @@
# DATABASES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
{% if cookiecutter.use_docker == "y" -%}
DATABASES = {"default": env.db("DATABASE_URL")}
{%- else %}
DATABASES = {
"default": env.db(
"DATABASE_URL",
default="postgres://{% if cookiecutter.windows == 'y' %}localhost{% endif %}/{{cookiecutter.project_slug}}",
),
}
{%- endif %}

if db_url := env.db("DATABASE_URL", default=None):
DATABASES = {"default": db_url}
else:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": env.str("POSTGRES_DB"),
"USER": env.str("POSTGRES_USER"),
"PASSWORD": env.str("POSTGRES_PASSWORD"),
"HOST": env.str("POSTGRES_HOST", default="{% if cookiecutter.windows == 'y' or cookiecutter.use_docker == 'n' %}localhost{%else%}postgres{% endif %}"),
"PORT": env.str("POSTGRES_PORT", default="5432"),
},
}

DATABASES["default"]["ATOMIC_REQUESTS"] = True
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
Expand Down