X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=sql%2Fbuilder.sh;h=16dafab82420f97b6698acf0a5a5b0d4b9e1bb8b;hb=6e93dcd90c31eebb95c96a7746b9846130904e3a;hp=e71d26e21f95c88d2fee2d5f0226f0bdb5c6dd4c;hpb=af5d80281ca7394f3365bbbeaabbe5d471ebe310;p=brisk.git diff --git a/sql/builder.sh b/sql/builder.sh index e71d26e..16dafab 100755 --- a/sql/builder.sh +++ b/sql/builder.sh @@ -8,8 +8,8 @@ DATECUR="$(date +%s)" # functions usage () { echo " USAGE" - echo " ./builder [-d|--dryrun] [-a|-p|--allfiles|--devfiles] [-s|--short] ..." - echo " ./builder <-h|--help|help>" + echo " $0 [-c|--config ] [-d|--dryrun] [<-a|--allfiles>|<-p|--devfiles>] [-s|--short] ..." + echo " $0 <-h|--help|help>" echo " commands are:" echo " create" echo " destroy" @@ -47,15 +47,25 @@ sqlexe () { } 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 + 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" } # @@ -67,6 +77,10 @@ shift while [ $# -gt 0 ]; do case $1 in + -c|--config) + CONFIG_FILE=$2 + shift + ;; -d|--dryrun) DRY_RUN=y psql () { @@ -107,6 +121,10 @@ if [ -f $HOME/.brisk_install ]; then source $HOME/.brisk_install fi +if [ -f "$CONFIG_FILE" ]; then + source "$CONFIG_FILE" +fi + pg_args="" test "$DBHOST" != "" && pg_args="$pg_args -h $DBHOST" test "$DBUSER" != "" && pg_args="$pg_args -U $DBUSER" @@ -125,13 +143,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 ;; @@ -160,10 +178,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