1 |
8161
|
aaronmk
|
#!/bin/bash
|
2 |
|
|
# Usage: (must be run from a table subdir)
|
3 |
|
|
if false; then
|
4 |
|
|
#!/bin/bash
|
5 |
|
|
cd "$(dirname "$0")"
|
6 |
|
|
. path/to/import.sh
|
7 |
|
|
|
8 |
|
|
map_table
|
9 |
|
|
psql <<'EOF'
|
10 |
|
|
postprocess_commands...
|
11 |
|
|
EOF
|
12 |
8198
|
aaronmk
|
mk_derived
|
13 |
8161
|
aaronmk
|
fi
|
14 |
|
|
|
15 |
|
|
import_sh_dir="$(dirname "${BASH_SOURCE[0]}")"
|
16 |
8193
|
aaronmk
|
root_dir="$import_sh_dir"/..
|
17 |
|
|
bin_dir="$root_dir"/bin
|
18 |
8161
|
aaronmk
|
|
19 |
8194
|
aaronmk
|
: "${schema="$(cd ..; basename "$PWD")"}"
|
20 |
|
|
: "${table="$(basename "$PWD")"}"
|
21 |
8195
|
aaronmk
|
export schema table
|
22 |
8161
|
aaronmk
|
|
23 |
|
|
psql ()
|
24 |
|
|
{
|
25 |
8196
|
aaronmk
|
(cat <<EOF
|
26 |
|
|
\set schema "$schema"
|
27 |
|
|
\set table "$table"
|
28 |
|
|
\set table_str '''"$table"'''
|
29 |
|
|
SET search_path TO "$schema", util;
|
30 |
|
|
EOF
|
31 |
|
|
cat)|
|
32 |
8161
|
aaronmk
|
env no_search_path=1 "$bin_dir"/psql_verbose_vegbien
|
33 |
|
|
}
|
34 |
|
|
|
35 |
|
|
map_table ()
|
36 |
|
|
{
|
37 |
8211
|
aaronmk
|
make --directory=.. --makefile=../input.Makefile "$table"/map.csv || return
|
38 |
8161
|
aaronmk
|
(psql <<EOF
|
39 |
8191
|
aaronmk
|
SELECT util.reset_map_table('pg_temp.map');
|
40 |
8161
|
aaronmk
|
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
|
41 |
8191
|
aaronmk
|
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
|
42 |
8161
|
aaronmk
|
EOF
|
43 |
8211
|
aaronmk
|
) || return
|
44 |
8161
|
aaronmk
|
}
|
45 |
8198
|
aaronmk
|
|
46 |
|
|
mk_derived () { "$root_dir"/schemas/VegCore/mk_derived; }
|