Project

General

Profile

1
#!/bin/bash -e
2

    
3
if false; then #### run script template:
4
#!/bin/bash -e
5
. "$(dirname "${BASH_SOURCE[0]}")"/path/to/table.run
6

    
7
import ()
8
{
9
	echo_func
10
	before_import_cmds
11
	"$(dirname "${BASH_SOURCE[0]}")"/path/to/table.run "$FUNCNAME" "$@"
12
	after_import_cmds
13
}
14
fi ####
15

    
16
. "$(dirname "${BASH_SOURCE[0]}")"/import.run
17
. "$(dirname "${BASH_SOURCE[0]}")"/../local.sh
18

    
19
if self_not_included; then
20

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

    
27
input_make ()
28
{
29
	echo_func
30
	extern make --directory="$top_dir"/.. "${@/#/$table/}"
31
}
32

    
33
map_table ()
34
{
35
	echo_func
36
	input_make map.csv
37
	psql <<EOF
38
SELECT util.reset_map_table('pg_temp.map');
39
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
40
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
41
EOF
42
}
43

    
44
mk_derived ()
45
{
46
	echo_func
47
	"$root_dir"/schemas/VegCore/mk_derived
48
}
49

    
50
remake_VegBIEN_mappings ()
51
{
52
	echo_func
53
	echo_run rm header.csv map.csv # remake them
54
	yes|input_make test
55
}
56

    
57
postprocess () # overridable
58
{
59
	echo_func
60
	local file="$top_dir"/postprocess.sql
61
	if test -e "$file"; then psql "$@"; fi
62
}
63

    
64
import ()
65
{
66
	echo_func
67
	map_table
68
	postprocess
69
	mk_derived
70
}
71

    
72
fi
(2-2/3)