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