Skip to content

Commit

Permalink
Switch to DATABASE_URL.
Browse files Browse the repository at this point in the history
For #34
  • Loading branch information
mblayman committed Aug 17, 2023
1 parent 9d8e8c1 commit 76b9653
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ACCOUNT_DEFAULT_HTTP_PROTOCOL=http
ALLOWED_HOSTS=*
CSRF_COOKIE_SECURE=off
DATABASE_SSL_REQUIRE=off
DATABASE_URL=sqlite:///db.sqlite3
DEBUG=on
EMAIL_BACKEND=django.core.mail.backends.console.EmailBackend
EMAIL_SENDGRID_REPLY_TO=[email protected]
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ jobs:
runs-on: ubuntu-22.04
env:
ALLOWED_HOSTS: '*'
DATABASE_SSL_REQUIRE: 'off'
EMAIL_SENDGRID_REPLY_TO: '[email protected]'
SECRET_KEY: 'a secret to everybody'
SECURE_SSL_REDIRECT: 'off'
SENDGRID_API_KEY: 'fake_apikey'
SENTRY_ENABLED: 'off'
SENTRY_DSN: 'dsn_example'
Expand Down Expand Up @@ -45,5 +47,5 @@ jobs:
- name: Check deploy configuration
run: ./manage.py check --deploy --fail-level WARNING
env:
# DATABASE_URL: 'sqlite://:memory:'
DATABASE_URL: 'sqlite://:memory:'
SECRET_KEY: 'zt(6jlr#oquxm2t%ryh#n+-72p^(3knbf&q$5x16#o%1im-s7!'
16 changes: 7 additions & 9 deletions project/settings.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from pathlib import Path

import dj_database_url
import environ

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

env = environ.Env(
ACCOUNT_DEFAULT_HTTP_PROTOCOL=(str, "https"),
ALLOWED_HOSTS=(list, []),
CSRF_COOKIE_SECURE=(bool, True),
DATABASE_CONN_MAX_AGE=(int, 600),
DATABASE_SSL_REQUIRE=(bool, True),
DEBUG=(bool, False),
EMAIL_BACKEND=(str, "anymail.backends.sendgrid.EmailBackend"),
SECURE_HSTS_SECONDS=(int, 60 * 60 * 24 * 365),
Expand All @@ -19,12 +21,9 @@
environ.Env.read_env(BASE_DIR / ".env")

SECRET_KEY = env("SECRET_KEY")

DEBUG = env("DEBUG")

ALLOWED_HOSTS: list[str] = env("ALLOWED_HOSTS")


# Application definition

INSTALLED_APPS = [
Expand Down Expand Up @@ -90,15 +89,14 @@

WSGI_APPLICATION = "project.wsgi.application"


# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
"default": dj_database_url.config(
conn_max_age=env("DATABASE_CONN_MAX_AGE"),
ssl_require=env("DATABASE_SSL_REQUIRE"),
)
}


Expand Down
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dj-database-url==2.1.0
Django==4.2.1
django-allauth==0.54.0
django-anymail[sendgrid]==10.1
Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ cryptography==41.0.0
# via pyjwt
defusedxml==0.7.1
# via python3-openid
dj-database-url==2.1.0
# via -r requirements.in
django==4.2.1
# via
# -r requirements.in
# dj-database-url
# django-allauth
# django-anymail
# django-extensions
Expand Down Expand Up @@ -57,6 +60,8 @@ sentry-sdk==1.28.1
# via -r requirements.in
sqlparse==0.4.4
# via django
typing-extensions==4.7.1
# via dj-database-url
urllib3==2.0.2
# via
# django-anymail
Expand Down

0 comments on commit 76b9653

Please sign in to comment.