Skip to content

Commit 2174ac8

Browse files
angela-tranthekaveman
authored andcommitted
feat: add script for resetting the database
1 parent d9b2c28 commit 2174ac8

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

bin/reset_db.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -eux
3+
4+
# remove database file
5+
6+
# construct the path to the database file from environment or default
7+
DB_DIR="${DJANGO_DB_DIR:-.}"
8+
DB_FILE="${DB_DIR}/django.db"
9+
10+
# -f forces the delete (and avoids an error when the file doesn't exist)
11+
rm -f "${DB_FILE}"
12+
13+
# run database migrations
14+
15+
python manage.py migrate
16+
17+
# create a superuser account for backend admin access
18+
# (set username, email, and password using environment variables
19+
# DJANGO_SUPERUSER_USERNAME, DJANGO_SUPERUSER_EMAIL, and DJANGO_SUPERUSER_PASSWORD)
20+
21+
python manage.py createsuperuser --no-input

docs/configuration/environment-variables.md

+12
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ By default the application sends logs to `stdout`.
126126

127127
Django's primary secret, keep this safe!
128128

129+
### `DJANGO_SUPERUSER_EMAIL`
130+
131+
The email address of the Django Admin superuser created when resetting the database.
132+
133+
### `DJANGO_SUPERUSER_PASSWORD`
134+
135+
The password of the Django Admin superuser created when resetting the database.
136+
137+
### `DJANGO_SUPERUSER_USERNAME`
138+
139+
The username of the Django Admin superuser created when resetting the database.
140+
129141
### `DJANGO_TRUSTED_ORIGINS`
130142

131143
!!! warning "Deployment configuration"

0 commit comments

Comments
 (0)