salix/db/import-changes.sh

69 lines
1.4 KiB
Bash
Raw Normal View History

2019-03-20 11:21:32 +00:00
#!/bin/bash
FORCE=FALSE
usage() {
echo "Usage: $0 [-f] [environment]"
exit 1
}
while getopts ":f" option
do
case $option in
f)
FORCE=TRUE
;;
\?|:)
usage
;;
esac
done
shift $(($OPTIND - 1))
ENV=$1
if [ "$ENV" == "production" ]; then
echo ""
echo " ( ( ) ( ( ) ) "
echo " )\ ))\ ) ( /( )\ ) ( * ))\ ) ( /( ( /( "
echo "(()/(()/( )\()|()/( ( )\ ) /(()/( )\()) )\())"
echo " /(_))(_)|(_)\ /(_)) )\ (((_) ( )(_))(_)|(_)\ ((_)\ "
echo "(_))(_)) ((_|_))_ _ ((_))\___(_(_()|_)) ((_) _((_)"
echo "| _ \ _ \ / _ \| \| | | ((/ __|_ _|_ _| / _ \| \| |"
echo "| _/ /| (_) | |) | |_| || (__ | | | | | (_) | . |"
echo "|_| |_|_\ \___/|___/ \___/ \___| |_| |___| \___/|_|\_|"
echo ""
if [ "$FORCE" != "TRUE" ]; then
read -p "Are you sure? (Default: no) [yes|no]: " ANSWER
if [ "$ANSWER" != "yes" ]; then
echo "Aborting"
exit;
fi
fi
fi
if [ -z "$ENV" ]; then
ENV="test"
fi
DIR="$(dirname "${BASH_SOURCE[0]}")"
INI_FILE="$DIR/config.$ENV.ini"
if [ ! -f "$INI_FILE" ]; then
echo "Config file doesn't exists: $INI_FILE"
exit 2
fi
echo "[INFO] Config file: $INI_FILE"
echo "[INFO] Applying changes"
# Import changes
2019-03-20 11:22:34 +00:00
2019-03-20 11:21:32 +00:00
for file in $DIR/install/changes/*.sql; do
echo "[INFO] -> $file"
mysql --defaults-file="$INI_FILE" < $file
done