4 MATCH_DROP='^DROP.*([^-]...|.[^-]..|..[^M].|...[^F])$|^ALTER TABLE.* DROP .*([^-]...|.[^-]..|..[^M].|...[^F])$|^DELETE .*([^-]...|.[^-]..|..[^M].|...[^F])$|--MB$'
10 echo " ./builder <command> [-d|--dryrun] [-a|--allfiles] [-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
49 if [ "$ALL_FILES" = "y" ]; then
55 if [ "$1" = "" ]; then
69 while [ $# -gt 0 ]; do
74 echo "MOCKPSQL params: $@"
91 if [ -f $HOME/.brisk-db.conf ]; then
92 source $HOME/.brisk-db.conf
93 elif [ -f $HOME/.db.conf ]; then
104 if [ -f $HOME/.brisk_install ]; then
105 source $HOME/.brisk_install
109 test "$DBHOST" != "" && pg_args="$pg_args -h $DBHOST"
110 test "$DBUSER" != "" && pg_args="$pg_args -U $DBUSER"
111 test "$DBPORT" != "" && pg_args="$pg_args -p $DBPORT"
112 test "$DBBASE" != "" && pg_args="$pg_args $DBBASE"
118 su root -c "su postgres -c \"echo \\\"DBUser passwd: $DBPASS\\\" ; createuser -S -D -R -P $DBUSER && createdb -E utf8 -O $DBUSER $DBBASE\""
123 su root -c "su postgres -c \"dropdb $DBBASE && dropuser $DBUSER\""
126 ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP" | tac ; echo "-- MESG: clean end" ; ) | sqlexe
129 ( echo "-- MESG: build start" ; one_or_all $2 | egrep -v "$MATCH_DROP" ; echo "-- MESG: build end" ; ) | sqlexe
132 ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP" | tac ; echo "-- MESG: clean end" ; \
133 echo "-- MESG: build start" ; one_or_all $2 | egrep -v "$MATCH_DROP" ; echo "-- MESG: build end" ; ) \
141 psql $pg_args -t -q -A -F '|' $@
144 if [ $# -eq 1 ]; then
145 pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE
147 pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE > $1
151 if [ $# -eq 1 ]; then
152 pg_dump -h $DBHOST -U $DBUSER $DBBASE
154 pg_dump -h $DBHOST -U $DBUSER $DBBASE > $1
158 ( echo "-- MESG: add start" ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: add end" ; ) | sqlexe
161 ( echo "-- MESG: del start" ; cat "$@" | egrep "$MATCH_DROP" | tac ; echo "-- MESG: del end" ; ) | sqlexe
164 ( echo "-- MESG: res start" ; cat "$@" | egrep "$MATCH_DROP" | tac ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: del end" ; ) | sqlexe
166 "help"|"-h"|"--help")