Project

General

Profile

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 8213 aaronmk
set -o errexit
16
17 8161 aaronmk
import_sh_dir="$(dirname "${BASH_SOURCE[0]}")"
18 8193 aaronmk
root_dir="$import_sh_dir"/..
19
bin_dir="$root_dir"/bin
20 8161 aaronmk
21 8194 aaronmk
: "${schema="$(cd ..; basename "$PWD")"}"
22
: "${table="$(basename "$PWD")"}"
23 8195 aaronmk
export schema table
24 8161 aaronmk
25
psql ()
26
{
27 8196 aaronmk
	(cat <<EOF
28
\set schema "$schema"
29
\set table "$table"
30
\set table_str '''"$table"'''
31
SET search_path TO "$schema", util;
32
EOF
33
	cat)|
34 8161 aaronmk
	env no_search_path=1 "$bin_dir"/psql_verbose_vegbien
35
}
36
37
map_table ()
38
{
39 8213 aaronmk
	make --directory=.. --makefile=../input.Makefile "$table"/map.csv
40 8214 aaronmk
	psql <<EOF
41 8191 aaronmk
SELECT util.reset_map_table('pg_temp.map');
42 8161 aaronmk
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
43 8191 aaronmk
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
44 8161 aaronmk
EOF
45
}
46 8198 aaronmk
47
mk_derived () { "$root_dir"/schemas/VegCore/mk_derived; }