4 MATCH_DROP='^DROP.*([^-]...|.[^-]..|..[^M].|...[^F])$|^ALTER TABLE.* DROP .*([^-]...|.[^-]..|..[^M].|...[^F])$|^DELETE .*([^-]...|.[^-]..|..[^M].|...[^F])$|--MB$'
11 echo " $0 <command> [-d|--dryrun] [<-a|--allfiles>|<-p|--devfiles>] [-s|--short] ..."
12 echo " $0 <-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
57 elif [ "$TYPE_FILES" = "a" ]; then
59 elif [ "$TYPE_FILES" = "d" ]; then
60 echo sql.d/[0-9]*.{sql,devel}
64 echo "-- FILE BEG: $fil"
66 echo "-- FILE END: $fil"
78 while [ $# -gt 0 ]; do
83 echo "MOCKPSQL params: $@"
103 if [ -f $HOME/.brisk-db.conf ]; then
104 source $HOME/.brisk-db.conf
105 elif [ -f $HOME/.db.conf ]; then
106 source $HOME/.db.conf
116 if [ -f $HOME/.brisk_install ]; then
117 source $HOME/.brisk_install
121 test "$DBHOST" != "" && pg_args="$pg_args -h $DBHOST"
122 test "$DBUSER" != "" && pg_args="$pg_args -U $DBUSER"
123 test "$DBPORT" != "" && pg_args="$pg_args -p $DBPORT"
124 test "$DBBASE" != "" && pg_args="$pg_args $DBBASE"
130 su root -c "su postgres -c \"echo \\\"DBUser passwd: $DBPASS\\\" ; createuser -S -D -R -P $DBUSER && createdb -E utf8 -O $DBUSER $DBBASE\""
135 su root -c "su postgres -c \"dropdb $DBBASE && dropuser $DBUSER\""
138 ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; echo "-- MESG: clean end" ; ) | sqlexe
141 ( echo "-- MESG: build start" ; one_or_all $2 | egrep -v "$MATCH_DROP" ; echo "-- MESG: build end" ; ) | sqlexe
144 ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; echo "-- MESG: clean end" ; \
145 echo "-- MESG: build start" ; one_or_all $2 | egrep -v "$MATCH_DROP" ; echo "-- MESG: build end" ; ) \
153 psql $pg_args -t -q -A -F '|' $@
156 if [ $# -eq 1 ]; then
157 pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE
159 pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE > $1
163 if [ $# -eq 1 ]; then
164 pg_dump -h $DBHOST -U $DBUSER $DBBASE
166 pg_dump -h $DBHOST -U $DBUSER $DBBASE > $1
170 ( echo "-- MESG: add start" ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: add end" ; ) | sqlexe
173 ( echo "-- MESG: del start" ; cat "$@" | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; echo "-- MESG: del end" ; ) | sqlexe
176 ( echo "-- MESG: res start" ; cat "$@" | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: del end" ; ) | sqlexe
178 "help"|"-h"|"--help")