Skip to content

Commit

Permalink
refactor:database configuration to use dbt_copilot utility
Browse files Browse the repository at this point in the history
Replaced the existing database connection logic with the `database_url_from_env` utility from `dbt_copilot_python` for cleaner and more standardized configuration. Removed the previous fallback logic for SQLite, assuming consistent reliance on environment variables.
  • Loading branch information
hareshkainthdbt committed Dec 12, 2024
1 parent b862768 commit 0ed8d6e
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 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,23 +109,28 @@
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",
}
}

DATABASES["default"] = dj_database_url.config( # noqa
default=database_url_from_env("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",
# }
# }

AUTH_PASSWORD_VALIDATORS = [
{
Expand Down

0 comments on commit 0ed8d6e

Please sign in to comment.