X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=sql%2Fbuilder.sh;h=4e144b98ba430256eb2327d457fe2bf2db100041;hb=f2074a7a29e3d8f60c605b7e4ab6de3a00234665;hp=3d145a6b6ce1eacb9058e1369ea49e3c6ae9bd69;hpb=be87b9bf51733dede3d9e7097769e5a03ee48e75;p=brisk.git diff --git a/sql/builder.sh b/sql/builder.sh index 3d145a6..4e144b9 100755 --- a/sql/builder.sh +++ b/sql/builder.sh @@ -3,6 +3,7 @@ # MATCH_DROP='^DROP.*([^-]...|.[^-]..|..[^M].|...[^F])$|^ALTER TABLE.* DROP .*([^-]...|.[^-]..|..[^M].|...[^F])$|^DELETE .*([^-]...|.[^-]..|..[^M].|...[^F])$|--MB$' +DATECUR="$(date +%s)" # functions usage () { @@ -37,24 +38,34 @@ sqlexe () { sht=$1 if [ "$SHORT" = "y" ]; then - sed "s/#PFX#/$PFX/g" | psql -a $pg_args 2>&1 | egrep 'ERROR|^-- MESG' + sed "s/#PFX#/$PFX/g;s/#NOW#/$DATECUR/g" | psql -a $pg_args 2>&1 | egrep 'ERROR|^-- MESG|^-- FILE ' else - sed "s/#PFX#/$PFX/g" | psql -a $pg_args + sed "s/#PFX#/$PFX/g;s/#NOW#/$DATECUR/g" | psql -a $pg_args fi return 0 } one_or_all() { - if [ "$1" ]; then - cat "$1" - elif [ "$TYPE_FILES" = "a" ]; then - cat sql.d/[0-9]* - elif [ "$TYPE_FILES" = "d" ]; then - cat sql.d/[0-9]*.{sql,devel} - else - cat sql.d/[0-9]*.sql - fi + local old_ifs + + old_ifs="$IFS" + IFS=" " + for fil in $( + if [ "$1" ]; then + echo "$1" + elif [ "$TYPE_FILES" = "a" ]; then + echo sql.d/[0-9]* + elif [ "$TYPE_FILES" = "d" ]; then + echo sql.d/[0-9]*.{sql,devel} + else + echo sql.d/[0-9]*.sql + fi); do + echo "-- FILE BEG: $fil" + cat "$fil" + echo "-- FILE END: $fil" + done + IFS="$old_ifs" } # @@ -124,13 +135,13 @@ case $CMD in su root -c "su postgres -c \"dropdb $DBBASE && dropuser $DBUSER\"" ;; "clean") - ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP" | tac ; echo "-- MESG: clean end" ; ) | sqlexe + ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; echo "-- MESG: clean end" ; ) | sqlexe ;; "build") ( echo "-- MESG: build start" ; one_or_all $2 | egrep -v "$MATCH_DROP" ; echo "-- MESG: build end" ; ) | sqlexe ;; "rebuild") - ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP" | tac ; echo "-- MESG: clean end" ; \ + ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; echo "-- MESG: clean end" ; \ echo "-- MESG: build start" ; one_or_all $2 | egrep -v "$MATCH_DROP" ; echo "-- MESG: build end" ; ) \ | sqlexe ;; @@ -159,10 +170,10 @@ case $CMD in ( echo "-- MESG: add start" ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: add end" ; ) | sqlexe ;; "del") - ( echo "-- MESG: del start" ; cat "$@" | egrep "$MATCH_DROP" | tac ; echo "-- MESG: del end" ; ) | sqlexe + ( echo "-- MESG: del start" ; cat "$@" | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; echo "-- MESG: del end" ; ) | sqlexe ;; "res") - ( echo "-- MESG: res start" ; cat "$@" | egrep "$MATCH_DROP" | tac ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: del end" ; ) | sqlexe + ( echo "-- MESG: res start" ; cat "$@" | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: del end" ; ) | sqlexe ;; "help"|"-h"|"--help") usage 0