diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1a3e5dd..b7d6939 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,6 +2,7 @@ + @@ -24,8 +25,8 @@ - - + + @@ -38,8 +39,8 @@ @@ -100,6 +101,7 @@ @@ -141,7 +143,7 @@ - + - @@ -265,8 +274,9 @@ + - + @@ -303,12 +313,12 @@ - - @@ -545,10 +555,20 @@ + + + + + + + + + + - - + + diff --git a/learning_log/database.py b/learning_log/database.py new file mode 100644 index 0000000..af8fbd9 --- /dev/null +++ b/learning_log/database.py @@ -0,0 +1,28 @@ +import os + +from django.conf import settings + +engines = { + 'sqlite': 'django.db.backends.sqlite3', + 'postgresql': 'django.db.backends.postgresql_psycopg2', +} + + +def config(): + service_name = os.getenv('DATABASE_SERVICE_NAME', '').upper().replace('-', + '_') + 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)), + } diff --git a/learning_log/settings.py b/learning_log/settings.py index 3e7931a..812ef4d 100644 --- a/learning_log/settings.py +++ b/learning_log/settings.py @@ -79,11 +79,10 @@ # Database # https://docs.djangoproject.com/en/2.1/ref/settings/#databases +from . import database + DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } + 'default': database.config() } # Password validation @@ -130,3 +129,5 @@ BOOTSTRAP3 = { 'include_jquery': True, } + +INTERNAL_IPS = ['127.0.0.1']