-
Notifications
You must be signed in to change notification settings - Fork 34
/
03_import_acs_2011_3yr.sh
executable file
·90 lines (77 loc) · 2.49 KB
/
03_import_acs_2011_3yr.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
# Clone the import scripts from git
cd /home/ubuntu
sudo apt-get -y install git
git clone git://github.com/censusreporter/census-postgres.git
# Create the schema
cd /home/ubuntu/census-postgres/acs2011_3yr
psql -d census -h localhost -U census -c "DROP SCHEMA IF EXISTS acs2011_3yr CASCADE; CREATE SCHEMA acs2011_3yr;"
# Create import tables
echo "Creating geoheader"
psql -d census -h localhost -U census -v ON_ERROR_STOP=1 -q -f create_geoheader.sql
if [[ $? != 0 ]]; then
echo "Failed creating geoheader."
exit 1
fi
echo "Creating geoheader comments"
psql -d census -h localhost -U census -v ON_ERROR_STOP=1 -q -f geoheader_comments.sql
if [[ $? != 0 ]]; then
echo "Failed creating geoheader comments."
exit 1
fi
echo "Creating temp geoheader"
psql -d census -h localhost -U census -v ON_ERROR_STOP=1 -q -f create_tmp_geoheader.sql
if [[ $? != 0 ]]; then
echo "Failed creating temp geoheader."
exit 1
fi
echo "Creating temp import tables"
psql -d census -h localhost -U census -v ON_ERROR_STOP=1 -q -f create_import_tables.sql
if [[ $? != 0 ]]; then
echo "Failed creating temp import tables."
exit 1
fi
# Slurp in the actual data
echo "Importing geoheader"
sudo -u postgres psql -d census -v ON_ERROR_STOP=1 -q -f import_geoheader.sql
if [[ $? != 0 ]]; then
echo "Failed importing geoheader."
exit 1
fi
echo "Parsing geoheader"
psql -d census -h localhost -U census -v ON_ERROR_STOP=1 -q -f parse_tmp_geoheader.sql
if [[ $? != 0 ]]; then
echo "Failed parsing geoheader."
exit 1
fi
echo "Importing sequences"
sudo -u postgres psql -d census -v ON_ERROR_STOP=1 -q -f import_sequences.sql # This takes ~5 minutes
if [[ $? != 0 ]]; then
echo "Failed importing sequences."
exit 1
fi
echo "Storing tables"
psql -d census -h localhost -U census -v ON_ERROR_STOP=1 -q -f store_by_tables.sql
if [[ $? != 0 ]]; then
echo "Failed storing tables."
exit 1
fi
echo "Inserting into tables"
psql -d census -h localhost -U census -v ON_ERROR_STOP=1 -q -f insert_into_tables.sql # This takes ~5 minutes
if [[ $? != 0 ]]; then
echo "Failed inserting into tables."
exit 1
fi
echo "Creating views"
psql -d census -h localhost -U census -v ON_ERROR_STOP=1 -q -f view_stored_by_tables.sql
if [[ $? != 0 ]]; then
echo "Failed creating views."
exit 1
fi
# Drop temp tables
echo "Dropping import tables"
psql -d census -h localhost -U census -v ON_ERROR_STOP=1 -q -f drop_import_tables.sql
if [[ $? != 0 ]]; then
echo "Failed dropping import tables."
exit 1
fi