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