DB import script fixes
gitea/salix/dev This commit looks good Details

This commit is contained in:
Juan Ferrer 2019-03-12 16:38:43 +01:00
parent 2c29ee2090
commit 0b560e1749
1 changed files with 32 additions and 8 deletions

View File

@ -1,5 +1,26 @@
#!/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
@ -14,12 +35,14 @@ if [ "$ENV" == "production" ]; then
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"
@ -28,15 +51,16 @@ fi
INI_FILE="config.$ENV.ini"
if [ ! -f "$INI_FILE" ]; then
echo "File $INI_FILE doesn't exists"
exit 1
echo "Config file doesn't exists: $INI_FILE"
exit 2
fi
echo "[INFO] Config file: $INI_FILE"
echo "[INFO] Importing changes."
echo "[INFO] Applying changes"
# Import changes
for file in install/changes/*.sql; do
echo "[INFO] -> Applying $file"
echo "[INFO] -> $file"
mysql --defaults-file="$INI_FILE" < $file
done