Skip to content

Instantly share code, notes, and snippets.

@nczz
Last active April 8, 2019 13:56
Show Gist options
  • Save nczz/a6c284fea6fc504376b616757877f212 to your computer and use it in GitHub Desktop.
Save nczz/a6c284fea6fc504376b616757877f212 to your computer and use it in GitHub Desktop.
檢查 iDempiere 資料庫是否有需要更新
#!/bin/bash
DATABASE=${1:-idempiere}
USER=adempiere
ADDPG=${2} # i.e. "-h localhost -p 5432"
MIGRATIONDIR=${3:-/Users/chun/eclipse-workspace/custom-idempiere/migration}
cd $MIGRATIONDIR
psql -d $DATABASE -U $USER $ADDPG -q -t -c "select name from adempiere.ad_migrationscript" | sed -e 's:^ ::' | grep -v '^$' | sort > /tmp/lisDB.txt
> /tmp/lisFS.txt
for FOLDER in i4.1 i4.1z i5.1 i5.1z i6.1 i6.1z i6.2
do
if [ -d ${FOLDER}/postgresql ]
then
cd ${FOLDER}/postgresql
ls *.sql | sort >> /tmp/lisFS.txt
cd ../..
fi
done
sort -o /tmp/lisFS.txt /tmp/lisFS.txt
sort -o /tmp/lisDB.txt /tmp/lisDB.txt
MSGERROR=""
APPLIED=N
for i in `comm -13 /tmp/lisDB.txt /tmp/lisFS.txt`
do
SCRIPT=`find . -name "$i" -print | fgrep -v /oracle/`
OUTFILE=/tmp/`basename "$i" .sql`.out
psql -d $DATABASE -U $USER $ADDPG -f "$SCRIPT" 2>&1 | tee "$OUTFILE"
if fgrep "ERROR:
FATAL:" "$OUTFILE" > /dev/null 2>&1
then
MSGERROR="$MSGERROR
**** ERROR ON FILE $OUTFILE - Please verify ****"
fi
APPLIED=Y
done
if [ x$APPLIED = xY ]
then
for i in processes_post_migration/postgresql/*.sql
do
OUTFILE=/tmp/`basename "$i" .sql`.out
psql -d $DATABASE -U $USER $ADDPG -f "$i" 2>&1 | tee "$OUTFILE"
if fgrep "ERROR:
FATAL:" "$OUTFILE" > /dev/null 2>&1
then
MSGERROR="$MSGERROR
**** ERROR ON FILE $OUTFILE - Please verify ****"
fi
done
else
echo "Database is up to date, no scripts to apply"
fi
if [ -n "$MSGERROR" ]
then
echo "$MSGERROR"
fi
# checkApplied.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment