1 |
8291
|
aaronmk
|
#!/bin/bash -e
|
2 |
8273
|
aaronmk
|
|
3 |
|
|
if false; then #### run script template:
|
4 |
8291
|
aaronmk
|
#!/bin/bash -e
|
5 |
8273
|
aaronmk
|
. "$(dirname "${BASH_SOURCE[0]}")"/path/to/table.run
|
6 |
8161
|
aaronmk
|
|
7 |
9039
|
aaronmk
|
func_override import__table_run
|
8 |
9074
|
aaronmk
|
import()
|
9 |
8273
|
aaronmk
|
{
|
10 |
8881
|
aaronmk
|
echo_func
|
11 |
8273
|
aaronmk
|
before_import_cmds
|
12 |
9039
|
aaronmk
|
import__table_run "$@"
|
13 |
8273
|
aaronmk
|
after_import_cmds
|
14 |
|
|
}
|
15 |
|
|
fi ####
|
16 |
8213
|
aaronmk
|
|
17 |
8296
|
aaronmk
|
. "$(dirname "${BASH_SOURCE[0]}")"/import.run
|
18 |
9013
|
aaronmk
|
. "$(dirname "${BASH_SOURCE[0]}")"/../sh/local.sh
|
19 |
9469
|
aaronmk
|
. "$(dirname "${BASH_SOURCE[0]}")"/../sh/make.sh
|
20 |
8273
|
aaronmk
|
|
21 |
8705
|
aaronmk
|
if self_not_included; then
|
22 |
|
|
|
23 |
9394
|
aaronmk
|
: "${schema="$(log+ 2 cd "$top_dir"/..; basename "$PWD")"}"
|
24 |
|
|
: "${table="$( log+ 2 cd "$top_dir" ; basename "$PWD")"}"
|
25 |
8195
|
aaronmk
|
export schema table
|
26 |
8161
|
aaronmk
|
|
27 |
9386
|
aaronmk
|
table_make() # usage: [silent=1] table_make target...
|
28 |
9355
|
aaronmk
|
# requires Makefile in datasrc dir with `include ../input.Makefile`
|
29 |
9386
|
aaronmk
|
# target names are relative to the table subdir itself, not the datasrc dir
|
30 |
9355
|
aaronmk
|
{
|
31 |
|
|
echo_func; kw_params silent
|
32 |
9388
|
aaronmk
|
make --directory="$(canon_rel_path "$top_dir"/..)" ${silent:+--silent }\
|
33 |
|
|
"${@/#/$table/}"
|
34 |
9387
|
aaronmk
|
# "${@/#/$table/}": replaces empty str at beginning of str (/#) with $table/
|
35 |
9355
|
aaronmk
|
}
|
36 |
8242
|
aaronmk
|
|
37 |
9074
|
aaronmk
|
map_table()
|
38 |
8161
|
aaronmk
|
{
|
39 |
8881
|
aaronmk
|
echo_func
|
40 |
9386
|
aaronmk
|
table_make map.csv
|
41 |
8214
|
aaronmk
|
psql <<EOF
|
42 |
8191
|
aaronmk
|
SELECT util.reset_map_table('pg_temp.map');
|
43 |
8161
|
aaronmk
|
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
|
44 |
8191
|
aaronmk
|
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
|
45 |
8161
|
aaronmk
|
EOF
|
46 |
|
|
}
|
47 |
8198
|
aaronmk
|
|
48 |
9350
|
aaronmk
|
mk_derived() { echo_func; "$root_dir"/schemas/VegCore/mk_derived; }
|
49 |
8245
|
aaronmk
|
|
50 |
9074
|
aaronmk
|
remake_VegBIEN_mappings()
|
51 |
8245
|
aaronmk
|
{
|
52 |
8881
|
aaronmk
|
echo_func
|
53 |
9047
|
aaronmk
|
public_schema_exists || return 0
|
54 |
9169
|
aaronmk
|
rm header.csv map.csv # remake them
|
55 |
9386
|
aaronmk
|
yes|table_make test
|
56 |
8245
|
aaronmk
|
}
|
57 |
8273
|
aaronmk
|
|
58 |
9074
|
aaronmk
|
postprocess() # overridable
|
59 |
8273
|
aaronmk
|
{
|
60 |
8881
|
aaronmk
|
echo_func
|
61 |
8273
|
aaronmk
|
local file="$top_dir"/postprocess.sql
|
62 |
|
|
if test -e "$file"; then psql "$@"; fi
|
63 |
|
|
}
|
64 |
|
|
|
65 |
9392
|
aaronmk
|
load_data()
|
66 |
|
|
{
|
67 |
|
|
echo_func
|
68 |
9408
|
aaronmk
|
verbosity_min=3 table_make ${remake:+re}install # just the table
|
69 |
|
|
# install logs require verbose output
|
70 |
9392
|
aaronmk
|
}
|
71 |
|
|
|
72 |
9074
|
aaronmk
|
import()
|
73 |
8273
|
aaronmk
|
{
|
74 |
8881
|
aaronmk
|
echo_func
|
75 |
9392
|
aaronmk
|
load_data
|
76 |
8282
|
aaronmk
|
map_table
|
77 |
|
|
postprocess
|
78 |
|
|
mk_derived
|
79 |
8273
|
aaronmk
|
}
|
80 |
8705
|
aaronmk
|
|
81 |
|
|
fi
|