fix logic on using remote mysql db. make sqlite the fall back, logic clears up if not all variables are set
This commit is contained in:
parent
5aef0ad5c9
commit
4c7ed9beb6
|
@ -4,10 +4,6 @@ MAINTAINER Jeffrey Forman <code@jeffreyforman.net>
|
|||
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
|
||||
# Uncomment the following line to not use a remote database,
|
||||
# and to use a local Sqlite database file.
|
||||
# ENV NODB 1
|
||||
|
||||
RUN apt-get update \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
# Django settings for binder project.
|
||||
import logging
|
||||
import os
|
||||
from django.contrib.messages import constants as messages
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
|
||||
DEBUG = True
|
||||
ADMINS = (
|
||||
|
@ -12,25 +15,31 @@ MANAGERS = ADMINS
|
|||
|
||||
ALLOWED_HOSTS=['*']
|
||||
|
||||
if os.getenv('NODB'):
|
||||
print "Attempting to use Sqlite database at %s" % (os.path.join(SITE_ROOT, 'db') + '/binder.db')
|
||||
DB_NAME = os.environ.get('DJANGO_DB_NAME', 'binder')
|
||||
DB_USER = os.environ.get('DJANGO_DB_USER', None)
|
||||
DB_PASSWORD = os.environ.get('DJANGO_DB_PASSWORD', None)
|
||||
DB_HOST = os.environ.get('DJANGO_DB_HOST', None)
|
||||
|
||||
if all([DB_NAME, DB_USER, DB_PASSWORD, DB_HOST]):
|
||||
logger.info("Using MySQL server for data backend.")
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': DB_NAME,
|
||||
'USER': DB_USER,
|
||||
'PASSWORD': DB_PASSWORD,
|
||||
'HOST': DB_HOST,
|
||||
'PORT': 3306,
|
||||
}
|
||||
}
|
||||
else:
|
||||
logger.info("Using Sqlite database at %s" % (os.path.join(SITE_ROOT, 'db') + '/binder.db'))
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(SITE_ROOT, 'db') + '/binder.db',
|
||||
}
|
||||
}
|
||||
else:
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': os.environ.get('DJANGO_DB_NAME', 'binder'),
|
||||
'USER': os.environ.get('DJANGO_DB_USER', ''),
|
||||
'PASSWORD': os.environ.get('DJANGO_DB_PASSWORD', ''),
|
||||
'HOST': os.environ.get('DJANGO_DB_HOST', ''),
|
||||
'PORT': 3306,
|
||||
}
|
||||
}
|
||||
|
||||
TIME_ZONE = 'America/New_York'
|
||||
|
||||
|
|
Loading…
Reference in New Issue