-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(rest_db): allow more local customization
* devs may or may not want to reset their local DB * devs may want to change which DB file is targeted * devs may want to change which fixture file is loaded update docs to reflect these changes
- Loading branch information
1 parent
aeaa3aa
commit 17f7164
Showing
4 changed files
with
104 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
DJANGO_SUPERUSER_USERNAME=benefits-admin | ||
DJANGO_SUPERUSER_EMAIL=[email protected] | ||
DJANGO_SUPERUSER_PASSWORD=superuser12345! | ||
|
||
DJANGO_DB_RESET=true | ||
DJANGO_DB_DIR=. | ||
DJANGO_DB_FILE=django.db | ||
DJANGO_DB_FIXTURES="benefits/core/migrations/local_fixtures.json" | ||
|
||
testsecret=Hello from the local environment! | ||
auth_provider_client_id=benefits-oauth-client-id | ||
courtesy_card_verifier_api_auth_key=server-auth-token | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,35 @@ | ||
#!/usr/bin/env bash | ||
set -eux | ||
|
||
# remove database file | ||
|
||
# construct the path to the database file from environment or default | ||
DB_DIR="${DJANGO_DB_DIR:-.}" | ||
DB_FILE="${DB_DIR}/django.db" | ||
|
||
# -f forces the delete (and avoids an error when the file doesn't exist) | ||
rm -f "${DB_FILE}" | ||
|
||
# run database migrations and other initialization | ||
|
||
bin/init.sh | ||
|
||
# create a superuser account for backend admin access | ||
# set username, email, and password using environment variables | ||
# DJANGO_SUPERUSER_USERNAME, DJANGO_SUPERUSER_EMAIL, and DJANGO_SUPERUSER_PASSWORD | ||
|
||
python manage.py createsuperuser --no-input | ||
|
||
# load sample data fixtures | ||
|
||
python manage.py loaddata benefits/core/migrations/local_fixtures.json | ||
# whether to reset database file, defaults to true | ||
DB_RESET="${DJANGO_DB_RESET:-true}" | ||
# optional fixtures to import | ||
FIXTURES="${DJANGO_DB_FIXTURES}" | ||
|
||
if [[ $DB_RESET = true ]]; then | ||
# construct the path to the database file from environment or default | ||
DB_DIR="${DJANGO_DB_DIR:-.}" | ||
DB_FILE="${DJANGO_DB_FILE:-django.db}" | ||
DB_PATH="${DB_DIR}/${DB_FILE}" | ||
|
||
rm -f "${DB_PATH}" | ||
|
||
# run database migrations and other initialization | ||
bin/init.sh | ||
|
||
# create a superuser account for backend admin access | ||
# set username, email, and password using environment variables | ||
# DJANGO_SUPERUSER_USERNAME, DJANGO_SUPERUSER_EMAIL, and DJANGO_SUPERUSER_PASSWORD | ||
python manage.py createsuperuser --no-input | ||
else | ||
echo "DB_RESET is false, skipping" | ||
fi | ||
|
||
valid_fixtures=$( echo $FIXTURES | grep -e fixtures\.json$ ) | ||
|
||
if [[ -n "$valid_fixtures" ]]; then | ||
# load data fixtures | ||
python manage.py loaddata "$FIXTURES" | ||
else | ||
echo "No JSON fixtures to load" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters