return 0
}
+one_or_all() {
+ if [ "$1" = "" ]; then
+ cat sql.d/*.sql
+ else
+ cat "$1"
+ fi
+}
+
#
# MAIN
#
echo "su root"
su root -c "su postgres -c \"dropdb $DBBASE && dropuser $DBUSER\""
elif [ "$1" = "clean" ]; then
- ( echo "-- MESG: clean start" ; cat sql.d/*.sql | grep -i '^drop' | tac ; echo "-- MESG: clean end" ; ) | sqlexe $sht
+ ( echo "-- MESG: clean start" ; one_or_all $2 | grep -i '^drop' | tac ; echo "-- MESG: clean end" ; ) | sqlexe $sht
elif [ "$1" = "build" ]; then
- ( echo "-- MESG: build start" ; cat sql.d/*.sql | grep -iv '^drop' ; echo "-- MESG: build end" ; ) | sqlexe $sht
+ ( echo "-- MESG: build start" ; one_or_all $2 | grep -iv '^drop' ; echo "-- MESG: build end" ; ) | sqlexe $sht
elif [ "$1" = "rebuild" ]; then
- ( echo "-- MESG: clean start" ; cat sql.d/*.sql | grep -i '^drop' | tac ; echo "-- MESG: clean end" ; \
- echo "-- MESG: build start" ; cat sql.d/*.sql | grep -iv '^drop' ; echo "-- MESG: build end" ; ) \
+ ( echo "-- MESG: clean start" ; one_or_all $2 | grep -i '^drop' | tac ; echo "-- MESG: clean end" ; \
+ echo "-- MESG: build start" ; one_or_all $2 | grep -iv '^drop' ; echo "-- MESG: build end" ; ) \
| sqlexe $sht
elif [ "$1" = "psql" ]; then
- psql -h $DBHOST -U $DBUSER $DBBASE
+ psql -h $DBHOST -U $DBUSER $DBBASE $@
+elif [ "$1" = "piped" ]; then
+ psql -h $DBHOST -U $DBUSER $DBBASE -t -q -A -F '|' $@
elif [ "$1" = "dump" ]; then
if [ $# -eq 1 ]; then
pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE
echo " ./builder build"
echo " ./builder rebuild"
echo " ./builder psql"
+ echo " ./builder piped"
echo " ./builder add <filesql>"
echo " ./builder dump [dumpfile]"
echo " ./builder dumpall [dumpfile]"