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
make()
38
{
39
	(set -x; env make --directory=.. --makefile=../input.Makefile \
40
"${@/#/$table/}")
41
}
42

    
43
map_table()
44
{
45
	make map.csv
46
	psql <<EOF
47
SELECT util.reset_map_table('pg_temp.map');
48
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
49
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
50
EOF
51
}
52

    
53
mk_derived() { "$root_dir"/schemas/VegCore/mk_derived; }
54

    
55
public_schema_exists()
56
{ "$bin_dir"/psql_script_vegbien </dev/null 2>/dev/null; }
57

    
58
remake_VegBIEN_mappings()
59
{
60
	public_schema_exists || return 0
61
	rm header.csv map.csv # remake them
62
	yes|make test
63
}
(21-21/50)