4 MATCH_DROP='^DROP.*([^-]...|.[^-]..|..[^M].|...[^F])$|^ALTER TABLE.* DROP .*([^-]...|.[^-]..|..[^M].|...[^F])$|^DELETE .*([^-]...|.[^-]..|..[^M].|...[^F])$|--MB$'
10 echo " ./builder <command> [-d|--dryrun] [-a|-p|--allfiles|--devfiles] [-s|--short] ..."
11 echo " ./builder <-h|--help|help>"
20 echo " add <filesql> [<filesql2> [..]]"
21 echo " del <filesql> [<filesql2> [..]]"
22 echo " res <filesql> [<filesql2> [..]]"
23 echo " dump [dumpfile]"
24 echo " dumpall [dumpfile]"
27 echo "The match rule for clean lines is:"
29 echo "NOTE: to invert normal 'del' rules add '--MF' (move forward) suffix to each line"
30 echo " to invert normal 'add' rules add '--MB' (move backward) suffix to each line"
39 if [ "$SHORT" = "y" ]; then
40 sed "s/#PFX#/$PFX/g" | psql -a $pg_args 2>&1 | egrep 'ERROR|^-- MESG'
42 sed "s/#PFX#/$PFX/g" | psql -a $pg_args
51 elif [ "$TYPE_FILES" = "a" ]; then
53 elif [ "$TYPE_FILES" = "d" ]; then
54 cat sql.d/[0-9]*.{sql,devel}
67 while [ $# -gt 0 ]; do
72 echo "MOCKPSQL params: $@"
92 if [ -f $HOME/.brisk-db.conf ]; then
93 source $HOME/.brisk-db.conf
94 elif [ -f $HOME/.db.conf ]; then
105 if [ -f $HOME/.brisk_install ]; then
106 source $HOME/.brisk_install
110 test "$DBHOST" != "" && pg_args="$pg_args -h $DBHOST"
111 test "$DBUSER" != "" && pg_args="$pg_args -U $DBUSER"
112 test "$DBPORT" != "" && pg_args="$pg_args -p $DBPORT"
113 test "$DBBASE" != "" && pg_args="$pg_args $DBBASE"
119 su root -c "su postgres -c \"echo \\\"DBUser passwd: $DBPASS\\\" ; createuser -S -D -R -P $DBUSER && createdb -E utf8 -O $DBUSER $DBBASE\""
124 su root -c "su postgres -c \"dropdb $DBBASE && dropuser $DBUSER\""
127 ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP" | tac ; echo "-- MESG: clean end" ; ) | sqlexe
130 ( echo "-- MESG: build start" ; one_or_all $2 | egrep -v "$MATCH_DROP" ; echo "-- MESG: build end" ; ) | sqlexe
133 ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP" | tac ; echo "-- MESG: clean end" ; \
134 echo "-- MESG: build start" ; one_or_all $2 | egrep -v "$MATCH_DROP" ; echo "-- MESG: build end" ; ) \
142 psql $pg_args -t -q -A -F '|' $@
145 if [ $# -eq 1 ]; then
146 pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE
148 pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE > $1
152 if [ $# -eq 1 ]; then
153 pg_dump -h $DBHOST -U $DBUSER $DBBASE
155 pg_dump -h $DBHOST -U $DBUSER $DBBASE > $1
159 ( echo "-- MESG: add start" ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: add end" ; ) | sqlexe
162 ( echo "-- MESG: del start" ; cat "$@" | egrep "$MATCH_DROP" | tac ; echo "-- MESG: del end" ; ) | sqlexe
165 ( echo "-- MESG: res start" ; cat "$@" | egrep "$MATCH_DROP" | tac ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: del end" ; ) | sqlexe
167 "help"|"-h"|"--help")