Skip to content

Commit

Permalink
in-memory database ?
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel-Therrien-Beslogic committed Oct 1, 2024
1 parent 99940e2 commit 4da28d3
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions canopeum_backend/canopeum_backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

import os
import sys
from datetime import timedelta
from pathlib import Path

Expand Down Expand Up @@ -170,17 +171,22 @@ def get_secret(key: str, default: str):

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

DATABASES = {
"default": dj_database_url.parse(
"mysql://{}:{}@{}:{}/canopeum_db".format(
get_secret("MYSQL_USER_CANOPEUM", "canopeum_user"),
get_secret("MYSQL_PASSWORD_CANOPEUM", ""),
get_secret("MYSQL_HOST_CANOPEUM", "localhost"),
get_secret("MYSQL_PORT_CANOPEUM", "3308"),
),
conn_max_age=600,
conn_health_checks=True,
"default": (
# If running Django tests, use an in-memory database,
# which is faster and requires less setup
{"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}
if sys.argv[1] == "test"
else dj_database_url.parse(
"mysql://{}:{}@{}:{}/canopeum_db".format(
get_secret("MYSQL_USER_CANOPEUM", "canopeum_user"),
get_secret("MYSQL_PASSWORD_CANOPEUM", ""),
get_secret("MYSQL_HOST_CANOPEUM", "localhost"),
get_secret("MYSQL_PORT_CANOPEUM", "3308"),
),
conn_max_age=600,
conn_health_checks=True,
)
),
# https://docs.djangoproject.com/en/5.1/ref/settings/#std-setting-DATABASE-TEST
# This matches the default MySQL database on GitHub CI
Expand All @@ -190,7 +196,8 @@ def get_secret(key: str, default: str):
"PORT": 3306,
},
}

if "test" in sys.argv:
DATABASES["default"] = {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}
# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators

Expand Down

0 comments on commit 4da28d3

Please sign in to comment.