Skip to content

Commit

Permalink
Fix: attempt db rename during reset (#1801)
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman authored Dec 1, 2023
2 parents f25d228 + 083e1bc commit 9ac066b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ benefits/static/sha.txt
__pycache__/
.coverage
.DS_Store
.venv
19 changes: 11 additions & 8 deletions bin/init.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#!/usr/bin/env bash
set -eux

# remove existing (old) database file

if [[ ${DJANGO_DB_RESET:-true} = true ]]; then
# construct the path to the database file from environment or default
DB_DIR="${DJANGO_DB_DIR:-.}"
DB_FILE="${DB_DIR}/django.db"
# make the path to the database file from environment or default
DB_DIR="${DJANGO_DB_DIR:-.}"
DB_FILE="${DB_DIR}/django.db"
DB_RESET="${DJANGO_DB_RESET:-true}"

# -f forces the delete (and avoids an error when the file doesn't exist)
rm -f "${DB_FILE}"
# remove existing (old) database file
if [[ $DB_RESET = true && -f $DB_FILE ]]; then
# rename then delete the new file
# trying to avoid a file lock on the existing file
# after marking it for deletion
mv "${DB_FILE}" "${DB_FILE}.old"
rm "${DB_FILE}.old"
fi

# run database migrations
Expand Down

0 comments on commit 9ac066b

Please sign in to comment.