Skip to content

Commit

Permalink
Merge pull request #126 from uktrade/feature/celery-deploy-fix
Browse files Browse the repository at this point in the history
refactor:database settings for dynamic credential handling
  • Loading branch information
hareshkainthdbt authored Dec 13, 2024
2 parents d64915b + 9130689 commit f82ec7f
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions fbr/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
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 @@ -109,30 +108,36 @@

WSGI_APPLICATION = "fbr.wsgi.application"

DATABASES: dict = {}
# if DATABASE_URL := env("DATABASE_URL", default=None):
# DATABASES = {
# "default": {
# **dj_database_url.parse(
# DATABASE_URL,
# engine="postgresql",
# ),
# "ENGINE": "django.db.backends.postgresql",
# }
# }
# else:
# DATABASES = {
# "default": {
# "ENGINE": "django.db.backends.sqlite3",
# "NAME": BASE_DIR / "db.sqlite3",
# }
# }

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

if DATABASE_URL := env("DATABASE_URL", default=None):
DATABASES = {
"default": {
**dj_database_url.parse(
DATABASE_URL,
engine="postgresql",
),
"ENGINE": "django.db.backends.postgresql",
}
}
else:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
DATABASES = {
"default": {
**dj_database_url.parse(
os.environ.get("DATABASE_CREDENTIALS"),
engine="postgresql",
),
"ENGINE": "django.db.backends.postgresql",
}

DATABASES["default"] = dj_database_url.config( # noqa
default=database_url_from_env("DATABASE_CREDENTIALS")
)
}

AUTH_PASSWORD_VALIDATORS = [
{
Expand Down

0 comments on commit f82ec7f

Please sign in to comment.