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 |
8924
|
aaronmk
|
bin_dir_abs="$(realpath "$bin_dir")"
|
10 |
8705
|
aaronmk
|
|
11 |
8708
|
aaronmk
|
export PATH="$bin_dir:$PATH"
|
12 |
|
|
|
13 |
8890
|
aaronmk
|
#### 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 |
8891
|
aaronmk
|
: "${postgres_compat=1}"
|
25 |
|
|
|
26 |
8777
|
aaronmk
|
mysql ()
|
27 |
|
|
{
|
28 |
8881
|
aaronmk
|
echo_func
|
29 |
8777
|
aaronmk
|
echo_run mysql_bien --database="$schema" --verbose "$@"
|
30 |
|
|
}
|
31 |
|
|
|
32 |
8892
|
aaronmk
|
mysqldump_local ()
|
33 |
|
|
{
|
34 |
|
|
echo_func
|
35 |
|
|
use_local_remote; mysqldump_diffable "$@"
|
36 |
|
|
}
|
37 |
|
|
|
38 |
8890
|
aaronmk
|
### PostgreSQL
|
39 |
|
|
|
40 |
8833
|
aaronmk
|
psql () # usage: [file=...] [dir=...] self
|
41 |
8777
|
aaronmk
|
{
|
42 |
8881
|
aaronmk
|
echo_func
|
43 |
8777
|
aaronmk
|
if test -n "$file"; then
|
44 |
|
|
set -- --file "$file" "$@"
|
45 |
8834
|
aaronmk
|
local dir="${dir:-$(dirname "$file")}"
|
46 |
8777
|
aaronmk
|
fi
|
47 |
8834
|
aaronmk
|
local dir="${dir:-$top_dir}"
|
48 |
8777
|
aaronmk
|
|
49 |
8790
|
aaronmk
|
local psql_cmd="psql_$(if log_sql; then echo verbose; else echo script; fi)_vegbien"
|
50 |
8777
|
aaronmk
|
(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 |
8873
|
aaronmk
|
env no_search_path=1 "$psql_cmd" --output /dev/fd/3 "$@" 3>&1 >&2
|
59 |
8777
|
aaronmk
|
}
|
60 |
|
|
|
61 |
8705
|
aaronmk
|
fi
|