Skip to content

Commit

Permalink
fix(init): rename then delete old database on reset
Browse files Browse the repository at this point in the history
trying to avoid a file lock on the existing file
after it has been marked for deletion
  • Loading branch information
thekaveman committed Dec 1, 2023
1 parent bbb9983 commit 083e1bc
Showing 1 changed file with 11 additions and 8 deletions.
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 083e1bc

Please sign in to comment.