X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=sql%2Fbuilder.sh;h=f67fa237663c20f6ec040eba7d9856cd328f4463;hb=f5a85bccf9d99d8489cb57f88f3b2c4ad69ae9c3;hp=da0596020bbbbf317cf07a0a89264f14c799421e;hpb=066415279e11ef282719a0c9a38ceba6465de785;p=brisk.git diff --git a/sql/builder.sh b/sql/builder.sh index da05960..f67fa23 100755 --- a/sql/builder.sh +++ b/sql/builder.sh @@ -3,12 +3,13 @@ # MATCH_DROP='^DROP.*([^-]...|.[^-]..|..[^M].|...[^F])$|^ALTER TABLE.* DROP .*([^-]...|.[^-]..|..[^M].|...[^F])$|^DELETE .*([^-]...|.[^-]..|..[^M].|...[^F])$|--MB$' +DATECUR="$(date +%s)" # functions usage () { echo " USAGE" - echo " ./builder [-d|--dryrun] [-a|--allfiles] [-s|--short] ..." - echo " ./builder <-h|--help|help>" + echo " $0 [-d|--dryrun] [<-a|--allfiles>|<-p|--devfiles>] [-s|--short] ..." + echo " $0 <-h|--help|help>" echo " commands are:" echo " create" echo " destroy" @@ -37,26 +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 [ "$ALL_FILES" = "y" ]; then - sfx_files='*' - else - sfx_files='*.sql' - fi - - if [ "$1" = "" ]; then - cat sql.d/$sfx_files - else - cat "$1" - fi + local old_ifs + + old_ifs="$IFS" + IFS=" " + for fil in $( + if [ "$1" ]; then + echo "$1" + elif [ "$TYPE_FILES" = "a" ]; then + find sql.d/ -name '[0-9]*' -type f | sort -n | tr '\n' ' ' + elif [ "$TYPE_FILES" = "d" ]; then + find sql.d/ -name '[0-9]*' | egrep '.*_devel.sql$|^[^_]+.sql$' | sort -n | tr '\n' ' ' + else + find sql.d/ -name '[0-9]*' | egrep '^[^_]+.sql$' | sort -n | tr '\n' ' ' + fi); do + echo "-- FILE BEG: $fil" + cat "$fil" + echo "-- FILE END: $fil" + done + IFS="$old_ifs" } # @@ -76,7 +85,10 @@ while [ $# -gt 0 ]; do } ;; -a|--allfiles) - ALL_FILES=y + TYPE_FILES=a + ;; + -p|--devfiles) + TYPE_FILES=d ;; -s|--short) SHORT=y @@ -123,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 ;; @@ -158,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