Project

General

Profile

1 8699 aaronmk
#!/bin/bash -e
2
# links to locally-available resources
3 8893 aaronmk
. "$(dirname "${BASH_SOURCE[0]}")"/util.sh
4 8699 aaronmk
5 8705 aaronmk
if self_not_included; then
6
7 8894 aaronmk
root_dir="$(dirname "${BASH_SOURCE[0]}")"/..
8 8699 aaronmk
bin_dir="$root_dir"/bin
9 8705 aaronmk
10 8708 aaronmk
export PATH="$bin_dir:$PATH"
11
12 8890 aaronmk
#### connection vars
13
14
: "${remote_server=vegbiendev.nceas.ucsb.edu}"
15
: "${local_server=localhost}"
16
: "${local_user=bien}"
17
: "${local_password="$(cat "$root_dir"/config/bien_password)"}"
18
19
#### databases
20
21
### MySQL
22
23 8891 aaronmk
: "${postgres_compat=1}"
24
25 8777 aaronmk
mysql ()
26
{
27 8881 aaronmk
	echo_func
28 8777 aaronmk
	echo_run mysql_bien --database="$schema" --verbose "$@"
29
}
30
31 8892 aaronmk
mysqldump_local ()
32
{
33
	echo_func
34
	use_local_remote; mysqldump_diffable "$@"
35
}
36
37 8890 aaronmk
### PostgreSQL
38
39 8833 aaronmk
psql () # usage: [file=...] [dir=...] self
40 8777 aaronmk
{
41 8881 aaronmk
	echo_func
42 8777 aaronmk
	if test -n "$file"; then
43
		set -- --file "$file" "$@"
44 8834 aaronmk
		local dir="${dir:-$(dirname "$file")}"
45 8777 aaronmk
	fi
46 8834 aaronmk
	local dir="${dir:-$top_dir}"
47 8777 aaronmk
48 8790 aaronmk
	local psql_cmd="psql_$(if log_sql; then echo verbose; else echo script; fi)_vegbien"
49 8777 aaronmk
	(cat <<EOF
50
\cd $dir
51
\set schema "$schema"
52
\set table "$table"
53
\set table_str '''"$table"'''
54
SET search_path TO "$schema", util;
55
EOF
56
	cat)|
57 8873 aaronmk
	env no_search_path=1 "$psql_cmd" --output /dev/fd/3 "$@" 3>&1 >&2
58 8777 aaronmk
}
59
60 8705 aaronmk
fi