radiostasis/db/run_migrations.sh

28 lines
477 B
Bash
Raw Normal View History

2023-03-26 11:37:20 -05:00
#!/usr/bin/env bash
set -euo pipefail
dbdir=$(dirname "$0")
db="$dbdir/radiostasis.db"
if ! command -v sqlite3 &>/dev/null; then
echo "sqlite3 not found on path"
exit 1
fi
if [ -f "$db" ]; then
echo -n "radiostasis.db already exists, delete and continue? [Y/n] "
read -r answer
if [[ "$answer" =~ ^[Nn]$ ]]; then
exit 0
else
rm "$db"
fi
fi
for sql in "$dbdir"/migrations/*.sql; do
2023-03-26 11:37:20 -05:00
echo "$sql..."
sqlite3 radiostasis.db < "$sql"
done
echo "Done."