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 #!/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 ENV=$1
if [ "$ENV" == "production" ]; then if [ "$ENV" == "production" ]; then
@ -14,11 +35,13 @@ if [ "$ENV" == "production" ]; then
echo "|_| |_|_\ \___/|___/ \___/ \___| |_| |___| \___/|_|\_|" echo "|_| |_|_\ \___/|___/ \___/ \___| |_| |___| \___/|_|\_|"
echo "" echo ""
read -p "Are you sure? (Default: no) [yes|no]: " ANSWER if [ "$FORCE" != "TRUE" ]; then
read -p "Are you sure? (Default: no) [yes|no]: " ANSWER
if [ "$ANSWER" != "yes" ]; then if [ "$ANSWER" != "yes" ]; then
echo "Aborting" echo "Aborting"
exit; exit;
fi
fi fi
fi fi
if [ -z "$ENV" ]; then if [ -z "$ENV" ]; then
@ -28,15 +51,16 @@ fi
INI_FILE="config.$ENV.ini" INI_FILE="config.$ENV.ini"
if [ ! -f "$INI_FILE" ]; then if [ ! -f "$INI_FILE" ]; then
echo "File $INI_FILE doesn't exists" echo "Config file doesn't exists: $INI_FILE"
exit 1 exit 2
fi fi
echo "[INFO] Config file: $INI_FILE" echo "[INFO] Config file: $INI_FILE"
echo "[INFO] Importing changes." echo "[INFO] Applying changes"
# Import changes # Import changes
for file in install/changes/*.sql; do for file in install/changes/*.sql; do
echo "[INFO] -> Applying $file" echo "[INFO] -> $file"
mysql --defaults-file="$INI_FILE" < $file mysql --defaults-file="$INI_FILE" < $file
done done