Skip to content

Commit

Permalink
refactor:database settings for dynamic credential handling
Browse files Browse the repository at this point in the history
Revised database configuration to retrieve credentials dynamically via `DATABASE_CREDENTIALS` from environment variables. Removed fallback to SQLite and deprecated `DATABASE_URL` usage. Added a debug statement to log database credentials for validation during setup.
  • Loading branch information
hareshkainthdbt committed Dec 13, 2024
1 parent d64915b commit 9130689
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 9130689

Please sign in to comment.