4 MATCH_DROP='^DROP.*([^-]...|.[^-]..|..[^M].|...[^F])$|^ALTER TABLE.* DROP .*([^-]...|.[^-]..|..[^M].|...[^F])$|^DELETE .*([^-]...|.[^-]..|..[^M].|...[^F])$|--MB$'
11 echo " ./builder <command> [-d|--dryrun] [-a|-p|--allfiles|--devfiles] [-s|--short] ..."
12 echo " ./builder <-h|--help|help>"
21 echo " add <filesql> [<filesql2> [..]]"
22 echo " del <filesql> [<filesql2> [..]]"
23 echo " res <filesql> [<filesql2> [..]]"
24 echo " dump [dumpfile]"
25 echo " dumpall [dumpfile]"
28 echo "The match rule for clean lines is:"
30 echo "NOTE: to invert normal 'del' rules add '--MF' (move forward) suffix to each line"
31 echo " to invert normal 'add' rules add '--MB' (move backward) suffix to each line"
40 if [ "$SHORT" = "y" ]; then
41 sed "s/#PFX#/$PFX/g;s/#NOW#/$DATECUR/g" | psql -a $pg_args 2>&1 | egrep 'ERROR|^-- MESG|^-- FILE '
43 sed "s/#PFX#/$PFX/g;s/#NOW#/$DATECUR/g" | psql -a $pg_args
52 elif [ "$TYPE_FILES" = "a" ]; then
54 elif [ "$TYPE_FILES" = "d" ]; then
55 cat sql.d/[0-9]*.{sql,devel}
68 while [ $# -gt 0 ]; do
73 echo "MOCKPSQL params: $@"
93 if [ -f $HOME/.brisk-db.conf ]; then
94 source $HOME/.brisk-db.conf
95 elif [ -f $HOME/.db.conf ]; then
106 if [ -f $HOME/.brisk_install ]; then
107 source $HOME/.brisk_install
111 test "$DBHOST" != "" && pg_args="$pg_args -h $DBHOST"
112 test "$DBUSER" != "" && pg_args="$pg_args -U $DBUSER"
113 test "$DBPORT" != "" && pg_args="$pg_args -p $DBPORT"
114 test "$DBBASE" != "" && pg_args="$pg_args $DBBASE"
120 su root -c "su postgres -c \"echo \\\"DBUser passwd: $DBPASS\\\" ; createuser -S -D -R -P $DBUSER && createdb -E utf8 -O $DBUSER $DBBASE\""
125 su root -c "su postgres -c \"dropdb $DBBASE && dropuser $DBUSER\""
128 ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP" | tac ; echo "-- MESG: clean end" ; ) | sqlexe
131 ( echo "-- MESG: build start" ; one_or_all $2 | egrep -v "$MATCH_DROP" ; echo "-- MESG: build end" ; ) | sqlexe
134 ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP" | tac ; echo "-- MESG: clean end" ; \
135 echo "-- MESG: build start" ; one_or_all $2 | egrep -v "$MATCH_DROP" ; echo "-- MESG: build end" ; ) \
143 psql $pg_args -t -q -A -F '|' $@
146 if [ $# -eq 1 ]; then
147 pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE
149 pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE > $1
153 if [ $# -eq 1 ]; then
154 pg_dump -h $DBHOST -U $DBUSER $DBBASE
156 pg_dump -h $DBHOST -U $DBUSER $DBBASE > $1
160 ( echo "-- MESG: add start" ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: add end" ; ) | sqlexe
163 ( echo "-- MESG: del start" ; cat "$@" | egrep "$MATCH_DROP" | tac ; echo "-- MESG: del end" ; ) | sqlexe
166 ( echo "-- MESG: res start" ; cat "$@" | egrep "$MATCH_DROP" | tac ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: del end" ; ) | sqlexe
168 "help"|"-h"|"--help")