2015-05-29 15:52:28 +02:00
|
|
|
import os
|
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
|
|
|
|
engines = {
|
|
|
|
'sqlite': 'django.db.backends.sqlite3',
|
|
|
|
'postgresql': 'django.db.backends.postgresql_psycopg2',
|
|
|
|
'mysql': 'django.db.backends.mysql',
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def config():
|
2017-02-02 10:10:49 +01:00
|
|
|
service_name = os.getenv('DATABASE_SERVICE_NAME', '').upper().replace('-', '_')
|
2015-05-29 15:52:28 +02:00
|
|
|
if service_name:
|
|
|
|
engine = engines.get(os.getenv('DATABASE_ENGINE'), engines['sqlite'])
|
|
|
|
else:
|
|
|
|
engine = engines['sqlite']
|
|
|
|
name = os.getenv('DATABASE_NAME')
|
|
|
|
if not name and engine == engines['sqlite']:
|
|
|
|
name = os.path.join(settings.BASE_DIR, 'db.sqlite3')
|
|
|
|
return {
|
|
|
|
'ENGINE': engine,
|
|
|
|
'NAME': name,
|
|
|
|
'USER': os.getenv('DATABASE_USER'),
|
|
|
|
'PASSWORD': os.getenv('DATABASE_PASSWORD'),
|
|
|
|
'HOST': os.getenv('{}_SERVICE_HOST'.format(service_name)),
|
|
|
|
'PORT': os.getenv('{}_SERVICE_PORT'.format(service_name)),
|
|
|
|
}
|