X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=sql%2Fbuilder.sh;h=3d145a6b6ce1eacb9058e1369ea49e3c6ae9bd69;hb=ef7ec88c07a56a9ef3a24c63a7e64ddfcdc830ad;hp=2f0e60c384d0af4591d1ca0e7a1174f9ea1ee6ab;hpb=cee6d187e4507bdc0af83f7ccf8a314bf897767e;p=brisk.git diff --git a/sql/builder.sh b/sql/builder.sh index 2f0e60c..3d145a6 100755 --- a/sql/builder.sh +++ b/sql/builder.sh @@ -1,10 +1,13 @@ #! /bin/bash - +# set -x # +MATCH_DROP='^DROP.*([^-]...|.[^-]..|..[^M].|...[^F])$|^ALTER TABLE.* DROP .*([^-]...|.[^-]..|..[^M].|...[^F])$|^DELETE .*([^-]...|.[^-]..|..[^M].|...[^F])$|--MB$' + + # functions usage () { echo " USAGE" - echo " ./builder [-d|--dryrun] [-a|--allfiles] [-s|--short] ..." + echo " ./builder [-d|--dryrun] [-a|-p|--allfiles|--devfiles] [-s|--short] ..." echo " ./builder <-h|--help|help>" echo " commands are:" echo " create" @@ -20,6 +23,12 @@ usage () { echo " dump [dumpfile]" echo " dumpall [dumpfile]" echo " all" + echo + echo "The match rule for clean lines is:" + echo " [$MATCH_DROP]" + echo "NOTE: to invert normal 'del' rules add '--MF' (move forward) suffix to each line" + echo " to invert normal 'add' rules add '--MB' (move backward) suffix to each line" + exit $1 } @@ -37,16 +46,14 @@ sqlexe () { } one_or_all() { - if [ "$ALL_FILES" = "y" ]; then - sfx_files='*' - else - sfx_files='*.sql' - fi - - if [ "$1" = "" ]; then - cat sql.d/$sfx_files - else + 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 } @@ -67,7 +74,10 @@ while [ $# -gt 0 ]; do } ;; -a|--allfiles) - ALL_FILES=y + TYPE_FILES=a + ;; + -p|--devfiles) + TYPE_FILES=d ;; -s|--short) SHORT=y @@ -102,7 +112,6 @@ test "$DBUSER" != "" && pg_args="$pg_args -U $DBUSER" test "$DBPORT" != "" && pg_args="$pg_args -p $DBPORT" test "$DBBASE" != "" && pg_args="$pg_args $DBBASE" -MATCH_DROP='^drop|^alter table.* drop |^delete ' case $CMD in "create") @@ -115,14 +124,14 @@ case $CMD in su root -c "su postgres -c \"dropdb $DBBASE && dropuser $DBUSER\"" ;; "clean") - ( echo "-- MESG: clean start" ; one_or_all $2 | egrep -i "$MATCH_DROP" | tac ; echo "-- MESG: clean end" ; ) | sqlexe + ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP" | tac ; echo "-- MESG: clean end" ; ) | sqlexe ;; "build") - ( echo "-- MESG: build start" ; one_or_all $2 | egrep -iv "$MATCH_DROP" ; echo "-- MESG: build end" ; ) | sqlexe + ( 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 -i "$MATCH_DROP" | tac ; echo "-- MESG: clean end" ; \ - echo "-- MESG: build start" ; one_or_all $2 | egrep -iv "$MATCH_DROP" ; echo "-- MESG: build end" ; ) \ + ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP" | tac ; echo "-- MESG: clean end" ; \ + echo "-- MESG: build start" ; one_or_all $2 | egrep -v "$MATCH_DROP" ; echo "-- MESG: build end" ; ) \ | sqlexe ;; "psql") @@ -147,13 +156,13 @@ case $CMD in fi ;; "add") - ( echo "-- MESG: add start" ; cat "$@" | egrep -iv "$MATCH_DROP" ; echo "-- MESG: add end" ; ) | sqlexe + ( echo "-- MESG: add start" ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: add end" ; ) | sqlexe ;; "del") - ( echo "-- MESG: del start" ; cat "$@" | egrep -i "$MATCH_DROP" | tac ; echo "-- MESG: del end" ; ) | sqlexe + ( echo "-- MESG: del start" ; cat "$@" | egrep "$MATCH_DROP" | tac ; echo "-- MESG: del end" ; ) | sqlexe ;; "res") - ( echo "-- MESG: res start" ; cat "$@" | egrep -i "$MATCH_DROP" | tac ; cat "$@" | egrep -iv "$MATCH_DROP" ; echo "-- MESG: del end" ; ) | sqlexe + ( echo "-- MESG: res start" ; cat "$@" | egrep "$MATCH_DROP" | tac ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: del end" ; ) | sqlexe ;; "help"|"-h"|"--help") usage 0