Skip to content

Commit e4794bc

Browse files
angela-tranthekaveman
authored andcommitted
refactor(admin): assume database and superuser already exist
1 parent 071a63b commit e4794bc

File tree

3 files changed

+0
-74
lines changed

3 files changed

+0
-74
lines changed

bin/init.sh

-23
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,10 @@
11
#!/usr/bin/env bash
22
set -eux
33

4-
# make the path to the database file from environment or default
5-
DB_DIR="${DJANGO_DB_DIR:-.}"
6-
DB_FILE="${DB_DIR}/django.db"
7-
DB_RESET="${DJANGO_DB_RESET:-true}"
8-
9-
# remove existing (old) database file
10-
if [[ $DB_RESET = true && -f $DB_FILE ]]; then
11-
# rename then delete the new file
12-
# trying to avoid a file lock on the existing file
13-
# after marking it for deletion
14-
mv "${DB_FILE}" "${DB_FILE}.old"
15-
rm "${DB_FILE}.old"
16-
fi
17-
184
# run database migrations
195

206
python manage.py migrate
217

22-
# create a superuser account for backend admin access
23-
# check DJANGO_ADMIN = true, default to false if empty or unset
24-
25-
if [[ ${DJANGO_ADMIN:-false} = true ]]; then
26-
python manage.py createsuperuser --no-input
27-
else
28-
echo "superuser: Django not configured for Admin access"
29-
fi
30-
318
# generate language *.mo files for use by Django
329

3310
python manage.py compilemessages

docs/configuration/environment-variables.md

-47
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,6 @@ writable by the Django process._
7878

7979
By default, the base project directory (i.e. the root of the repository).
8080

81-
### `DJANGO_DB_RESET`
82-
83-
!!! warning "Deployment configuration"
84-
85-
You may change this setting when deploying the app to a non-localhost domain
86-
87-
Boolean:
88-
89-
- `True` (default): deletes the existing database file and runs fresh Django migrations.
90-
- `False`: Django uses the existing database file.
91-
9281
### `DJANGO_DEBUG`
9382

9483
!!! warning "Deployment configuration"
@@ -144,42 +133,6 @@ By default the application sends logs to `stdout`.
144133

145134
Django's primary secret, keep this safe!
146135

147-
### `DJANGO_SUPERUSER_EMAIL`
148-
149-
!!! warning "Deployment configuration"
150-
151-
You may change this setting when deploying the app to a non-localhost domain
152-
153-
!!! danger "Required configuration"
154-
155-
This setting is required when `DJANGO_ADMIN` is `true`
156-
157-
The email address of the Django Admin superuser created during initialization.
158-
159-
### `DJANGO_SUPERUSER_PASSWORD`
160-
161-
!!! warning "Deployment configuration"
162-
163-
You may change this setting when deploying the app to a non-localhost domain
164-
165-
!!! danger "Required configuration"
166-
167-
This setting is required when `DJANGO_ADMIN` is `true`
168-
169-
The password of the Django Admin superuser created during initialization.
170-
171-
### `DJANGO_SUPERUSER_USERNAME`
172-
173-
!!! warning "Deployment configuration"
174-
175-
You may change this setting when deploying the app to a non-localhost domain
176-
177-
!!! danger "Required configuration"
178-
179-
This setting is required when `DJANGO_ADMIN` is `true`
180-
181-
The username of the Django Admin superuser created during initialization.
182-
183136
### `DJANGO_TRUSTED_ORIGINS`
184137

185138
!!! warning "Deployment configuration"

terraform/app_service.tf

-4
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,8 @@ resource "azurerm_linux_web_app" "main" {
6969
"DJANGO_ADMIN" = "${local.secret_prefix}django-admin)",
7070
"DJANGO_ALLOWED_HOSTS" = "${local.secret_prefix}django-allowed-hosts)",
7171
"DJANGO_DB_DIR" = "${local.secret_prefix}django-db-dir)",
72-
"DJANGO_DB_RESET" = "${local.secret_prefix}django-db-reset)",
7372
"DJANGO_DEBUG" = local.is_prod ? null : "${local.secret_prefix}django-debug)",
7473
"DJANGO_LOG_LEVEL" = "${local.secret_prefix}django-log-level)",
75-
"DJANGO_SUPERUSER_EMAIL" = "${local.secret_prefix}django-superuser-email)",
76-
"DJANGO_SUPERUSER_PASSWORD" = "${local.secret_prefix}django-superuser-password)",
77-
"DJANGO_SUPERUSER_USERNAME" = "${local.secret_prefix}django-superuser-username)",
7874

7975
"DJANGO_RECAPTCHA_SECRET_KEY" = local.is_dev ? null : "${local.secret_prefix}django-recaptcha-secret-key)",
8076
"DJANGO_RECAPTCHA_SITE_KEY" = local.is_dev ? null : "${local.secret_prefix}django-recaptcha-site-key)",

0 commit comments

Comments
 (0)