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
func_override import__table_run
8
import()
9
{
10
	echo_func
11
	before_import_cmds
12
	import__table_run "$@"
13
	after_import_cmds
14
}
15
fi ####
16

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

    
20
if self_not_included; then
21

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

    
28
input_make() { echo_func; make --directory="$top_dir"/.. "${@/#/$table/}"; }
29

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

    
41
mk_derived() { echo_func; "$root_dir"/schemas/VegCore/mk_derived; }
42

    
43
remake_VegBIEN_mappings()
44
{
45
	echo_func
46
	public_schema_exists || return 0
47
	rm header.csv map.csv # remake them
48
	yes|input_make test
49
}
50

    
51
postprocess() # overridable
52
{
53
	echo_func
54
	local file="$top_dir"/postprocess.sql
55
	if test -e "$file"; then psql "$@"; fi
56
}
57

    
58
import()
59
{
60
	echo_func
61
	map_table
62
	postprocess
63
	mk_derived
64
}
65

    
66
fi
(2-2/3)