dotfiles/bin/riesel

29 lines
800 B
Plaintext
Raw Normal View History

2020-01-15 10:41:11 +00:00
#!/usr/bin/env bash
# Looks for the Rocket.toml and uses the database url in it to run diesel
# commands.
while [ ! -f Rocket.toml ]; do
cd ..
if [ "$PWD" == "/" ]; then
echo -e >&2 "\033[31;1merror:\033[0m unable to find a Rocket.toml"
exit 1
fi
done
url=$(cat Rocket.toml | grep url | cut -d '"' -f 2)
2020-07-20 09:05:06 +01:00
if [ $# -eq 3 ] && [ "$1" == "migration" ] && [ "$2" == "redo" ] && [ "$3" == "all" ]; then
for i in `ls migrations`; do
diesel --database-url $url migration revert
done
diesel --database-url $url migration run
elif [ $# -eq 3 ] && [ "$1" == "migration" ] && [ "$2" == "revert" ] && [ "$3" == "all" ]; then
for i in `ls migrations`; do
diesel --database-url $url migration revert
done
else
diesel --database-url $url $@
fi