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="$(log+ 2 cd "$top_dir"/..; basename "$PWD")"}"
23
mk_esc_name schema
24
: "${table="$( log+ 2 cd "$top_dir"   ; basename "$PWD")"}"
25
mk_esc_name table
26
export schema table
27

    
28
table_make() # usage: [silent=1] table_make target...
29
# requires Makefile in datasrc dir with `include ../input.Makefile`
30
# target names are relative to the table subdir itself, not the datasrc dir
31
{
32
	echo_func; kw_params silent
33
	make --directory="$(canon_rel_path "$top_dir"/..)" ${silent:+--silent }\
34
"${@/#/$table/}"
35
	# "${@/#/$table/}": replaces empty str at beginning of str (/#) with $table/
36
}
37

    
38
map_table()
39
{
40
	echo_func
41
	table_make map.csv
42
	psql <<EOF
43
SELECT util.reset_map_table('pg_temp.map');
44
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
45
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
46
EOF
47
}
48

    
49
mk_derived() { echo_func; "$root_dir"/schemas/VegCore/mk_derived; }
50

    
51
remake_VegBIEN_mappings()
52
{
53
	echo_func
54
	public_schema_exists || return 0
55
	rm header.csv map.csv # remake them
56
	yes|table_make test
57
}
58

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

    
66
load_data()
67
{
68
	echo_func
69
	verbosity_min=3 table_make ${remake:+re}install # just the table
70
		# install logs require verbose output
71
}
72

    
73
import()
74
{
75
	echo_func
76
	load_data
77
	map_table
78
	postprocess
79
	mk_derived
80
}
81

    
82
fi
(2-2/3)