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
	self_make import__table_run "$@"
13
	after_import_cmds
14
}
15
fi ####
16

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

    
21
if self_not_included; then
22

    
23
: "${table=$subdir}"; export table
24

    
25
table_make() { subdir_make "$@"; }
26

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

    
38
mk_derived() { echo_func; "$root_dir"/schemas/VegCore/mk_derived; }
39

    
40
remake_VegBIEN_mappings()
41
{
42
	echo_func
43
	public_schema_exists || return 0
44
	rm header.csv map.csv # remake them
45
	yes|table_make test
46
}
47

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

    
55
load_data()
56
{
57
	echo_func
58
	verbosity_min=3 table_make ${remake:+re}install # just the table
59
		# install logs require verbose output
60
}
61

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

    
71
fi
(4-4/5)