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
install_log="$top_dir"/logs/install.log.sql
56

    
57
load_data()
58
{
59
	echo_func
60
	local verbosity_min=3 # install logs require verbose output
61
	set -- table_make ${remake:+re}install # just the table
62
	if remaking || test ! -e "$install_log"; then "$@" # OK to clobber log
63
	else benign_error=1 noclobber=1 "$@" || true
64
	fi
65
}
66

    
67
import()
68
{
69
	echo_func
70
	load_data
71
	map_table
72
	postprocess
73
	mk_derived
74
}
75

    
76
fi
(5-5/6)