4 MATCH_DROP='^DROP.*([^-]...|.[^-]..|..[^M].|...[^F])$|^ALTER TABLE.* DROP .*([^-]...|.[^-]..|..[^M].|...[^F])$|^DELETE .*([^-]...|.[^-]..|..[^M].|...[^F])$|--MB$'
12 echo " $0 <command> [-c|--config <override_file>] [-d|--dryrun] [<-a|--allfiles>|<-p|--devfiles>] [-s|--short] ..."
13 echo " $0 [-c|--config <override_file>] <-h|--help|help>"
22 echo " add <filesql> [<filesql2> [..]]"
23 echo " del <filesql> [<filesql2> [..]]"
24 echo " res <filesql> [<filesql2> [..]]"
25 echo " dump [dumpfile]"
26 echo " dumpall [dumpfile]"
29 echo "The match rule for clean lines is:"
31 echo "NOTE: to invert normal 'del' rules add '--MF' (move forward) suffix to each line"
32 echo " to invert normal 'add' rules add '--MB' (move backward) suffix to each line"
36 apache_conf card_hand players_n tables_n tables_appr_n tables_auth_n tables_cert_n \
37 brisk_auth_conf brisk_debug web_path ftok_path proxy_path legal_path prefix_path \
38 brisk_conf usock_path sys_user web_only test_add \
39 DBHOST DBUSER DBPORT DBBASE DBPASS PFX ; do
50 if [ "$SHORT" = "y" ]; then
51 sed "s/#PFX#/$PFX/g;s/#NOW#/$DATECUR/g" | psql -a $pg_args 2>&1 | egrep 'ERROR|^-- MESG|^-- FILE '
53 sed "s/#PFX#/$PFX/g;s/#NOW#/$DATECUR/g" | psql -a $pg_args
67 elif [ "$TYPE_FILES" = "a" ]; then
68 find sql.d/ -name '[0-9]*' -type f | sort -n | tr '\n' ' '
69 elif [ "$TYPE_FILES" = "d" ]; then
70 find sql.d/ -name '[0-9]*' | egrep '.*_devel.sql$|^[^_]+.sql$' | sort -n | tr '\n' ' '
72 find sql.d/ -name '[0-9]*' | egrep '^[^_]+.sql$' | sort -n | tr '\n' ' '
74 echo "-- FILE BEG: $fil"
76 echo "-- FILE END: $fil"
84 if [ "${1:0:1}" != "-" ]; then
89 while [ $# -gt 0 ]; do
98 echo "MOCKPSQL params: $@"
121 if [ -f $HOME/.brisk-db.conf ]; then
122 source $HOME/.brisk-db.conf
123 elif [ -f $HOME/.db.conf ]; then
124 source $HOME/.db.conf
134 if [ -f $HOME/.brisk_install ]; then
135 source $HOME/.brisk_install
138 if [ -f "$CONFIG_FILE" ]; then
139 source "$CONFIG_FILE"
143 test "$DBHOST" != "" && pg_args="$pg_args -h $DBHOST"
144 test "$DBUSER" != "" && pg_args="$pg_args -U $DBUSER"
145 test "$DBPORT" != "" && pg_args="$pg_args -p $DBPORT"
146 test "$DBBASE" != "" && pg_args="$pg_args $DBBASE"
152 su root -c "su postgres -c \"echo \\\"DBUser passwd: $DBPASS\\\" ; createuser -S -D -R -P $DBUSER && createdb -E utf8 -O $DBUSER $DBBASE\""
157 su root -c "su postgres -c \"dropdb $DBBASE && dropuser $DBUSER\""
160 ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; echo "-- MESG: clean end" ; ) | sqlexe
163 ( echo "-- MESG: build start" ; one_or_all $2 | egrep -v "$MATCH_DROP" ; echo "-- MESG: build end" ; ) | sqlexe
166 ( echo "-- MESG: clean start" ; one_or_all $2 | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; echo "-- MESG: clean end" ; \
167 echo "-- MESG: build start" ; one_or_all $2 | egrep -v "$MATCH_DROP" ; echo "-- MESG: build end" ; ) \
175 psql $pg_args -t -q -A -F '|' $@
178 if [ $# -eq 1 ]; then
179 pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE
181 pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE > $1
185 if [ $# -eq 1 ]; then
186 pg_dump -h $DBHOST -U $DBUSER $DBBASE
188 pg_dump -h $DBHOST -U $DBUSER $DBBASE > $1
192 ( echo "-- MESG: add start" ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: add end" ; ) | sqlexe
195 ( echo "-- MESG: del start" ; cat "$@" | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; echo "-- MESG: del end" ; ) | sqlexe
198 ( echo "-- MESG: res start" ; cat "$@" | egrep "$MATCH_DROP|^-- MESG|^-- FILE " | tac ; cat "$@" | egrep -v "$MATCH_DROP" ; echo "-- MESG: del end" ; ) | sqlexe
200 "help"|"-h"|"--help")