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
.rel subdir.run
19
.rel ../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; set_make_vars
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()
39
{ echo_func; set_make_vars; "$root_dir"/schemas/VegCore/mk_derived; }
40

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

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

    
56
install_log="$top_dir"/logs/install.log.sql
57

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

    
68
import()
69
{
70
	echo_func; set_make_vars
71
	self_make load_data
72
	map_table
73
	postprocess
74
	mk_derived
75
}
76

    
77
fi
(5-5/6)