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 |
8273
|
aaronmk
|
import ()
|
8 |
|
|
{
|
9 |
8463
|
aaronmk
|
echo_func "$@"
|
10 |
8273
|
aaronmk
|
before_import_cmds
|
11 |
8301
|
aaronmk
|
"$(dirname "${BASH_SOURCE[0]}")"/path/to/table.run "$FUNCNAME" "$@"
|
12 |
8273
|
aaronmk
|
after_import_cmds
|
13 |
|
|
}
|
14 |
|
|
fi ####
|
15 |
8213
|
aaronmk
|
|
16 |
8296
|
aaronmk
|
. "$(dirname "${BASH_SOURCE[0]}")"/import.run
|
17 |
8701
|
aaronmk
|
. "$(dirname "${BASH_SOURCE[0]}")"/local.run
|
18 |
8273
|
aaronmk
|
|
19 |
8705
|
aaronmk
|
if self_not_included; then
|
20 |
|
|
|
21 |
8273
|
aaronmk
|
: "${schema="$(cd "$top_dir"/..; basename "$PWD")"}"
|
22 |
8696
|
aaronmk
|
mk_esc_name schema
|
23 |
8273
|
aaronmk
|
: "${table="$( cd "$top_dir" ; basename "$PWD")"}"
|
24 |
8696
|
aaronmk
|
mk_esc_name table
|
25 |
8195
|
aaronmk
|
export schema table
|
26 |
8161
|
aaronmk
|
|
27 |
8273
|
aaronmk
|
input_make ()
|
28 |
8242
|
aaronmk
|
{
|
29 |
8463
|
aaronmk
|
echo_func "$@"
|
30 |
8277
|
aaronmk
|
echo_run env make --directory="$top_dir"/.. "${@/#/$table/}"
|
31 |
8242
|
aaronmk
|
}
|
32 |
|
|
|
33 |
8161
|
aaronmk
|
map_table ()
|
34 |
|
|
{
|
35 |
8463
|
aaronmk
|
echo_func "$@"
|
36 |
8273
|
aaronmk
|
input_make map.csv
|
37 |
8214
|
aaronmk
|
psql <<EOF
|
38 |
8191
|
aaronmk
|
SELECT util.reset_map_table('pg_temp.map');
|
39 |
8161
|
aaronmk
|
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
|
40 |
8191
|
aaronmk
|
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
|
41 |
8161
|
aaronmk
|
EOF
|
42 |
|
|
}
|
43 |
8198
|
aaronmk
|
|
44 |
8282
|
aaronmk
|
mk_derived ()
|
45 |
|
|
{
|
46 |
8463
|
aaronmk
|
echo_func "$@"
|
47 |
8282
|
aaronmk
|
"$root_dir"/schemas/VegCore/mk_derived
|
48 |
|
|
}
|
49 |
8245
|
aaronmk
|
|
50 |
|
|
remake_VegBIEN_mappings ()
|
51 |
|
|
{
|
52 |
8463
|
aaronmk
|
echo_func "$@"
|
53 |
8277
|
aaronmk
|
echo_run rm header.csv map.csv # remake them
|
54 |
8273
|
aaronmk
|
yes|input_make test
|
55 |
8245
|
aaronmk
|
}
|
56 |
8273
|
aaronmk
|
|
57 |
|
|
postprocess () # overridable
|
58 |
|
|
{
|
59 |
8463
|
aaronmk
|
echo_func "$@"
|
60 |
8273
|
aaronmk
|
local file="$top_dir"/postprocess.sql
|
61 |
|
|
if test -e "$file"; then psql "$@"; fi
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
import ()
|
65 |
|
|
{
|
66 |
8463
|
aaronmk
|
echo_func "$@"
|
67 |
8282
|
aaronmk
|
map_table
|
68 |
|
|
postprocess
|
69 |
|
|
mk_derived
|
70 |
8273
|
aaronmk
|
}
|
71 |
8705
|
aaronmk
|
|
72 |
|
|
fi
|