Skip to content

Commit

Permalink
feat: update env system for database
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew4Coding committed Oct 11, 2024
1 parent ab26939 commit d1c27d7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_NAME=
DB_USER=
DB_PASSWORD=
DB_HOST=
DB_PORT=
20 changes: 19 additions & 1 deletion eventyog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from pathlib import Path
import os
from dotenv import load_dotenv

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand Down Expand Up @@ -79,8 +80,25 @@

# Database
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
# Add these at the top of your settings.py

DATABASES = {

load_dotenv() # Load environment variables from a .env file

if PRODUCTION:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.getenv('DB_NAME', 'eventyog'),
'USER': os.getenv('DB_USER', 'pemilos24_owner'),
'PASSWORD': os.getenv('DB_PASSWORD', 'DRzSsw7Pc2HE'),
'HOST': os.getenv('DB_HOST', 'ep-late-cloud-a1j1feg2-pooler.ap-southeast-1.aws.neon.tech'),
'PORT': os.getenv('DB_PORT', 5432),
}
}

else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ gunicorn
whitenoise
psycopg2-binary
requests
urllib3
urllib3
python-dotenv

0 comments on commit d1c27d7

Please sign in to comment.