Project

General

Profile

1
#!/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
mk_derived
13
fi
14

    
15
set -o errexit
16

    
17
import_sh_dir="$(dirname "${BASH_SOURCE[0]}")"
18
root_dir="$import_sh_dir"/..
19
bin_dir="$root_dir"/bin
20

    
21
: "${schema="$(cd ..; basename "$PWD")"}"
22
: "${table="$(basename "$PWD")"}"
23
export schema table
24

    
25
psql ()
26
{
27
	(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
	env no_search_path=1 "$bin_dir"/psql_verbose_vegbien
35
}
36

    
37
map_table ()
38
{
39
	make --directory=.. --makefile=../input.Makefile "$table"/map.csv
40
	psql <<EOF
41
SELECT util.reset_map_table('pg_temp.map');
42
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
43
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
44
EOF
45
}
46

    
47
mk_derived () { "$root_dir"/schemas/VegCore/mk_derived; }
(20-20/48)