1
|
#!/bin/bash
|
2
|
# Usage: (must be run from a table subdir)
|
3
|
if false; then
|
4
|
#!/bin/bash
|
5
|
cd "$(dirname "$0")"
|
6
|
. path/to/import.sh
|
7
|
|
8
|
map_table
|
9
|
psql <<'EOF'
|
10
|
postprocess_commands...
|
11
|
EOF
|
12
|
mk_derived
|
13
|
fi
|
14
|
|
15
|
import_sh_dir="$(dirname "${BASH_SOURCE[0]}")"
|
16
|
root_dir="$import_sh_dir"/..
|
17
|
bin_dir="$root_dir"/bin
|
18
|
|
19
|
: "${schema="$(cd ..; basename "$PWD")"}"
|
20
|
: "${table="$(basename "$PWD")"}"
|
21
|
export schema table
|
22
|
|
23
|
psql ()
|
24
|
{
|
25
|
(cat <<EOF
|
26
|
\set schema "$schema"
|
27
|
\set table "$table"
|
28
|
\set table_str '''"$table"'''
|
29
|
SET search_path TO "$schema", util;
|
30
|
EOF
|
31
|
cat)|
|
32
|
env no_search_path=1 "$bin_dir"/psql_verbose_vegbien
|
33
|
}
|
34
|
|
35
|
map_table ()
|
36
|
{
|
37
|
make --directory=.. --makefile=../input.Makefile "$table"/map.csv || return
|
38
|
(psql <<EOF
|
39
|
SELECT util.reset_map_table('pg_temp.map');
|
40
|
\copy pg_temp.map FROM 'map.csv' CSV HEADER;
|
41
|
SELECT util.set_col_names('"$table"', 'pg_temp.map'::regclass);
|
42
|
EOF
|
43
|
) || return
|
44
|
}
|
45
|
|
46
|
mk_derived () { "$root_dir"/schemas/VegCore/mk_derived; }
|