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 8242 aaronmk
make ()
38
{
39
	(set -x; env make --directory=.. --makefile=../input.Makefile \
40
"${@/#/$table/}")
41
}
42
43 8161 aaronmk
map_table ()
44
{
45 8242 aaronmk
	make map.csv
46 8214 aaronmk
	psql <<EOF
47 8191 aaronmk
SELECT util.reset_map_table('pg_temp.map');
48 8161 aaronmk
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
49 8191 aaronmk
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
50 8161 aaronmk
EOF
51
}
52 8198 aaronmk
53
mk_derived () { "$root_dir"/schemas/VegCore/mk_derived; }
54 8245 aaronmk
55
remake_VegBIEN_mappings ()
56
{
57
	rm header.csv map.csv # remake them
58 8246 aaronmk
	yes|make test
59 8245 aaronmk
}