feat: Store database credentials in a separate configuration file

This commit is contained in:
Lord_Devi 2024-09-16 21:47:02 -04:00
parent a774ae23eb
commit b65fd05fb1
3 changed files with 19 additions and 5 deletions

3
.gitignore vendored
View file

@ -22,3 +22,6 @@ db.sqlite3-journal
# OS-specific files
.DS_Store
Thumbs.db
# Database configuration
config/database.ini

6
config/database.ini Normal file
View file

@ -0,0 +1,6 @@
[postgresql]
host=barad-dur.lan.mgk.one
database=leadsdb
user=melkor
password=Th3leetnis!leadsdb
port=5433

View file

@ -12,10 +12,15 @@ https://docs.djangoproject.com/en/4.2/ref/settings/
import os
from pathlib import Path
import configparser
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Read database configuration
config = configparser.ConfigParser()
config.read(os.path.join(BASE_DIR, 'config', 'database.ini'))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
@ -78,11 +83,11 @@ WSGI_APPLICATION = 'leadsdb.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'leadsdb',
'USER': 'melkor',
'PASSWORD': 'Th3leetnis!leadsdb',
'HOST': 'barad-dur.lan.mgk.one',
'PORT': '5433',
'NAME': config['postgresql']['database'],
'USER': config['postgresql']['user'],
'PASSWORD': config['postgresql']['password'],
'HOST': config['postgresql']['host'],
'PORT': config['postgresql']['port'],
}
}