Add support for DB config overrides to base settings

Closes #273
This commit is contained in:
Christopher C. Wells 2021-08-06 08:52:51 -07:00
parent 858436e840
commit ddf4c70739
2 changed files with 13 additions and 23 deletions

View File

@ -101,12 +101,19 @@ TEMPLATES = [
# Database # Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases # https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = { config = {'ENGINE': os.getenv('DB_ENGINE') or 'django.db.backends.sqlite3'}
'default': { if os.getenv('DB_NAME'):
'ENGINE': 'django.db.backends.sqlite3', config['NAME'] = os.getenv('DB_NAME')
'NAME': os.path.join(BASE_DIR, 'data/db.sqlite3'), if os.getenv('DB_USER'):
} config['USER'] = os.getenv('DB_USER')
} if os.environ.get('DB_PASSWORD') or os.environ.get('POSTGRES_PASSWORD'):
config['PASSWORD'] = os.environ.get('DB_PASSWORD') or os.environ.get('POSTGRES_PASSWORD')
if os.getenv('DB_HOST'):
config['HOST'] = os.getenv('DB_HOST')
if os.getenv('DB_PORT'):
config['PORT'] = os.getenv('DB_PORT')
DATABASES = {'default': config}
# Cache # Cache

View File

@ -1,17 +0,0 @@
from .base import *
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
# Load settings from env file / variables with fallback defaults to support current psql deployment
DATABASES = {
'default': {
'ENGINE': os.getenv('DB_ENGINE') or 'django.db.backends.postgresql_psycopg2',
'NAME': os.getenv('DB_NAME') or 'postgres',
'USER': os.getenv('DB_USER') or 'postgres',
'PASSWORD': os.environ.get('DB_PASSWORD') or os.environ.get('POSTGRES_PASSWORD'),
'HOST': os.getenv('DB_HOST') or 'db',
'PORT': os.getenv('DB_PORT') or 5432,
}
}