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() # usage: [silent=1] input_make target...
29
# requires Makefile in datasrc dir with `include ../input.Makefile`
30
{
31
	echo_func; kw_params silent
32
	make --directory="$top_dir"/.. ${silent:+--silent }"${@/#/$table/}"
33
}
34
	# "${@/#/$table/}": replaces empty str at beginning of str (/#) with $table/
35

    
36
map_table()
37
{
38
	echo_func
39
	input_make 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() { echo_func; "$root_dir"/schemas/VegCore/mk_derived; }
48

    
49
remake_VegBIEN_mappings()
50
{
51
	echo_func
52
	public_schema_exists || return 0
53
	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)