projects
/
brisk.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
inverted logic in a test
[brisk.git]
/
sql
/
builder.sh
diff --git
a/sql/builder.sh
b/sql/builder.sh
index
89f3624
..
221bd87
100755
(executable)
--- a/
sql/builder.sh
+++ b/
sql/builder.sh
@@
-3,16
+3,22
@@
#
# all this part is from mopshop and we will use it to construct the brisk database
#
#
# all this part is from mopshop and we will use it to construct the brisk database
#
-DBHOST=127.0.0.1
-DBUSER=brisk
-DBBASE=brisk
-DBPASS=briskpass
-PFX="bsk_"
+
+if [ -f $HOME/.db.conf ]; then
+ source $HOME/.db.conf
+else
+ DBHOST=127.0.0.1
+ DBUSER=brisk
+ DBBASE=brisk
+ DBPASS=briskpass
+ PFX="bsk_"
+fi
if [ -f $HOME/.brisk_install ]; then
if [ -f $HOME/.brisk_install ]; then
-
.
$HOME/.brisk_install
+
source
$HOME/.brisk_install
fi
fi
+
sqlexe () {
local sht
sht=$1
sqlexe () {
local sht
sht=$1
@@
-26,13
+32,18
@@
sqlexe () {
return 0
}
return 0
}
+one_or_all() {
+ if [ "$1" = "" ]; then
+ cat sql.d/*.sql
+ else
+ cat "$1"
+ fi
+}
+
#
# MAIN
#
sht=0
#
# MAIN
#
sht=0
-if [ -f $HOME/.db.conf ]; then
- source $HOME/.db.conf
-fi
if [ "$1" = "-s" ]; then
shift
if [ "$1" = "-s" ]; then
shift
@@
-46,29
+57,31
@@
elif [ "$1" = "destroy" ]; then
echo "su root"
su root -c "su postgres -c \"dropdb $DBBASE && dropuser $DBUSER\""
elif [ "$1" = "clean" ]; then
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
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
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
| 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
elif [ "$1" = "dump" ]; then
- if [ $# -eq 1 ]; then
- pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE
- else
- pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE > $2
- fi
+
if [ $# -eq 1 ]; then
+
pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE
+
else
+
pg_dump -a --inserts -h $DBHOST -U $DBUSER $DBBASE > $2
+
fi
elif [ "$1" = "dumpall" ]; then
elif [ "$1" = "dumpall" ]; then
- if [ $# -eq 1 ]; then
- pg_dump -h $DBHOST -U $DBUSER $DBBASE
- else
- pg_dump -h $DBHOST -U $DBUSER $DBBASE > $2
- fi
+
if [ $# -eq 1 ]; then
+
pg_dump -h $DBHOST -U $DBUSER $DBBASE
+
else
+
pg_dump -h $DBHOST -U $DBUSER $DBBASE > $2
+
fi
elif [ "$1" = "add" ]; then
elif [ "$1" = "add" ]; then
- cat "$2" | psql -h $DBHOST -U $DBUSER $DBBASE
+
cat "$2" | psql -h $DBHOST -U $DBUSER $DBBASE
else
echo " USAGE"
echo " ./builder create"
else
echo " USAGE"
echo " ./builder create"
@@
-77,6
+90,7
@@
else
echo " ./builder build"
echo " ./builder rebuild"
echo " ./builder psql"
echo " ./builder build"
echo " ./builder rebuild"
echo " ./builder psql"
+ echo " ./builder piped"
echo " ./builder add <filesql>"
echo " ./builder dump [dumpfile]"
echo " ./builder dumpall [dumpfile]"
echo " ./builder add <filesql>"
echo " ./builder dump [dumpfile]"
echo " ./builder dumpall [dumpfile]"