Database toggle
This commit is contained in:
parent
17650b72ba
commit
a29f4e627e
2 changed files with 29 additions and 25 deletions
|
@ -15,15 +15,6 @@ import os
|
|||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
|
||||
def get_env_value(env_variable, default):
|
||||
try:
|
||||
return os.environ[env_variable]
|
||||
except KeyError:
|
||||
return default
|
||||
# error_msg = 'Set the {} environment variable'.format(env_variable)
|
||||
# raise ImproperlyConfigured(error_msg)
|
||||
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
@ -90,16 +81,24 @@ WSGI_APPLICATION = 'KeRS.wsgi.application'
|
|||
# Database
|
||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': get_env_value('DATABASE_NAME', 'kers'),
|
||||
'USER': get_env_value('DATABASE_USER', 'kers'),
|
||||
'PASSWORD': get_env_value('DATABASE_PASSWORD', 'kers'),
|
||||
'HOST': get_env_value('DATABASE_HOST', '127.0.0.1'),
|
||||
'PORT': get_env_value('DATABASE_PORT', '3306'),
|
||||
if os.getenv('KERS_DB_BACKEND', 'mysql') == 'sqlite3':
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.getenv('KERS_SQLITE_FILE', 'kers.sqlite3'),
|
||||
}
|
||||
}
|
||||
else:
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': os.getenv('DATABASE_NAME', 'kers'),
|
||||
'USER': os.getenv('DATABASE_USER', 'kers'),
|
||||
'PASSWORD': os.getenv('DATABASE_PASSWORD', 'kers'),
|
||||
'HOST': os.getenv('DATABASE_HOST', '127.0.0.1'),
|
||||
'PORT': os.getenv('DATABASE_PORT', '3306'),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
|
||||
|
@ -142,8 +141,8 @@ STATICFILES_DIRS = [
|
|||
|
||||
# Celery
|
||||
|
||||
CELERY_BROKER = get_env_value('CELERY_BROKER', 'redis://localhost:6379/0')
|
||||
CELERY_BACKEND = get_env_value('CELERY_BACKEND', 'redis://localhost:6379/1')
|
||||
CELERY_BROKER = os.getenv('CELERY_BROKER', 'redis://localhost:6379/0')
|
||||
CELERY_BACKEND = os.getenv('CELERY_BACKEND', 'redis://localhost:6379/1')
|
||||
# Custom stuff
|
||||
|
||||
SERVER_URL = 'http://localhost:8000'
|
||||
|
|
15
Makefile
15
Makefile
|
@ -1,4 +1,5 @@
|
|||
SQLITE_FILE ?= kers.sqlite3
|
||||
KERS_DB_BACKEND ?= mysql
|
||||
KERS_SQLITE_FILE ?= kers.sqlite3
|
||||
KERS_SUPERUSER_ZEUSID ?= 1
|
||||
KERS_SUPERUSER_NAME ?= admin
|
||||
KERS_SUPERUSER_PASSWORD ?= admin
|
||||
|
@ -28,11 +29,15 @@ superuser:
|
|||
(sleep 1; echo "$(KERS_SUPERUSER_PASSWORD)"; sleep 0.5; echo "$(KERS_SUPERUSER_PASSWORD)"; sleep 1; echo "y") | \
|
||||
socat - EXEC:'$(PYTHON) manage.py createsuperuser --username $(KERS_SUPERUSER_NAME) --zeus_id $(KERS_SUPERUSER_ZEUSID)',pty,setsid,ctty
|
||||
|
||||
.PHONY: rewrite_migrations
|
||||
.PHONY: reset_db rewrite_migrations
|
||||
reset_db:
|
||||
case "$(KERS_DB_BACKEND)" in \
|
||||
mysql) printf "Please drop your MySQL/MariaDB tables and press enter"; read; ;; \
|
||||
sqlite3) rm -f "$(SQLITE_FILE)"; ;; \
|
||||
esac
|
||||
make migrate
|
||||
rewrite_migrations:
|
||||
@printf "Only for when there is no data in production yet. Continue? (y/N) "; read continue; [ "$$continue" = y ]
|
||||
rm -f events/migrations/0*_*.py users/migrations/0*_*.py
|
||||
rm -f "$(SQLITE_FILE)"
|
||||
make migrations
|
||||
make migrate
|
||||
make superuser
|
||||
make reset_db
|
||||
|
|
Loading…
Reference in a new issue