Skip to content

Commit

Permalink
Merge pull request #127 from uktrade/feature/celery-deploy-fix
Browse files Browse the repository at this point in the history
refactor:database configuration logic in settings.py
  • Loading branch information
hareshkainthdbt authored Dec 13, 2024
2 parents f82ec7f + 7e72f57 commit 92f0612
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions fbr/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import dj_database_url
import environ

from dbt_copilot_python.database import database_url_from_env
from django_log_formatter_asim import ASIMFormatter

# Define the root directory (i.e. <repo-root>)
Expand Down Expand Up @@ -108,6 +109,8 @@

WSGI_APPLICATION = "fbr.wsgi.application"

DATABASES: dict = {}

# if DATABASE_URL := env("DATABASE_URL", default=None):
# DATABASES = {
# "default": {
Expand All @@ -126,18 +129,17 @@
# }
# }

# Print to console DATABASE_CREDENTIALS
print(f"DATABASE_CREDENTIALS: {os.environ.get('DATABASE_CREDENTIALS')}")

DATABASES = {
"default": {
**dj_database_url.parse(
os.environ.get("DATABASE_CREDENTIALS"),
engine="postgresql",
),
"ENGINE": "django.db.backends.postgresql",
}
}
if DATABASE_URL := env("DATABASE_CREDENTIALS", default=None):
DATABASES["default"] = dj_database_url.config( # noqa
default=database_url_from_env("DATABASE_CREDENTIALS")
)
else:
DATABASES["default"] = dj_database_url.parse(
'{"pw":"postgres","dbname":"fbr","engine":"postgres",'
'"port":5432,"dbInstanceIdentifier":"xxx","host":"db",'
'"username":"postgres"}',
engine="postgresql",
)

AUTH_PASSWORD_VALIDATORS = [
{
Expand Down

0 comments on commit 92f0612

Please sign in to comment.