dotfiles/bin/riesel

29 lines
800 B
Bash
Executable File

#!/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)
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