Skip to content

Commit 7343fc6

Browse files
committed
commit all
1 parent efbce6b commit 7343fc6

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

backend/.env

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ SECRET_KEY=!s9g(4l%hn$$k8hqq6sodks2ni22!%6l+=8r3xygj%ho6vx2c%k
44
ALLOWED_HOSTS=localhost,127.0.0.1,atonixdev.org,api.atonixdev.org,www.atonixdev.org
55

66
# Database
7+
# Local dev default (SQLite). Docker Compose overrides DB_HOST/DB_* as needed.
8+
DATABASE_URL=sqlite:///db.sqlite3
9+
DB_HOST=
710
DB_NAME=personal_brand_hub
811
DB_USER=postgres
912
DB_PASSWORD=postgres
10-
DB_HOST=db
1113
DB_PORT=5432
1214

1315
# CORS Settings

backend/config/settings.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
from datetime import timedelta
88
from decouple import config, Csv
99

10+
try:
11+
import dj_database_url
12+
except Exception: # pragma: no cover
13+
dj_database_url = None
14+
1015
# Build paths inside the project like this: BASE_DIR / 'subdir'.
1116
BASE_DIR = Path(__file__).resolve().parent.parent
1217

@@ -88,8 +93,18 @@
8893
WSGI_APPLICATION = 'config.wsgi.application'
8994

9095
# Database
91-
# Use PostgreSQL when DB_HOST is provided via environment; fall back to SQLite for local dev.
92-
if config('DB_HOST', default=None):
96+
# Prefer DATABASE_URL when provided (works for local dev + production), else fall back to DB_HOST-based Postgres,
97+
# else fall back to SQLite.
98+
DATABASE_URL = config('DATABASE_URL', default='').strip()
99+
100+
if DATABASE_URL and dj_database_url:
101+
DATABASES = {
102+
'default': dj_database_url.parse(
103+
DATABASE_URL,
104+
conn_max_age=60,
105+
)
106+
}
107+
elif config('DB_HOST', default=None):
93108
DATABASES = {
94109
'default': {
95110
'ENGINE': 'django.db.backends.postgresql',

backend/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ gunicorn==21.2.0
99
whitenoise==6.6.0
1010
django-filter==23.5
1111
requests==2.32.3
12+
dj-database-url==2.3.0
1213
setuptools>=70.0.0

0 commit comments

Comments
 (0)