-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
191 lines (165 loc) · 4.25 KB
/
Makefile
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
include .env
sched ?= "0 0 * * *"
message ?= "{}"
limit ?= 50
install:
pip install virtualenv
virtualenv venv
source venv/bin/activate
deploy:
gcloud functions deploy ingest_feeds_$(name)\
--entry-point main\
--source ingest_feeds/$(name)\
--runtime python37\
--trigger-resource ingest_feeds_$(name)\
--trigger-event google.pubsub.topic.publish\
--timeout 540s\
--set-env-vars PROJECT=${PROJECT}\
--set-env-vars BUCKET=${BUCKET}\
--set-env-vars TOKEN=cloud
schedule:
gcloud scheduler jobs create pubsub ingest_feeds_$(name)_job\
--schedule $(schedule)\
--topic ingest_feeds_$(name)\
--message-body $(message)
trigger:
gcloud pubsub topics publish ingest_feeds_$(name)\
--message "$(message)";
log:
gcloud functions logs read --limit $(limit)
clean:
rm -rf build;
mkdir -p build;
createdb: clean
# cleanup build directory
rm -rf build;
mkdir -p build;
# load all DDLs into one SQL file, in order of foreign constraint dependencies
cat\
sql/date/staging-ddl.sql\
sql/census_tiger/staging-ddl.sql\
sql/census_hhp/staging-ddl.sql\
sql/census_demographics/staging-ddl.sql\
sql/jhu_covid19/staging-ddl.sql\
sql/acled_ccc_events/staging-ddl.sql\
> build/makedb.sql;
# run SQL file
mysql\
--host="${MYSQL_HOST}"\
--user="${MYSQL_USER}"\
--password="${MYSQL_PASSWORD}"\
-D covid\
< build/makedb.sql;
# cleanup
#rm -rf build;
importdb:
# create date table first
mysql\
--host="${MYSQL_HOST}"\
--user="${MYSQL_USER}"\
--password="${MYSQL_PASSWORD}"\
-D covid\
< sql/date/staging-dml.sql;
# import all CSVs - in order of foreign constraint dependencies
mysqlimport\
--host="${MYSQL_HOST}"\
--user="${MYSQL_USER}"\
--password="${MYSQL_PASSWORD}"\
--local\
--ignore-lines 1\
--lines-terminated-by "\n"\
--fields-terminated-by ","\
--fields-optionally-enclosed-by '"'\
covid\
data/import/csa.csv\
data/import/msa.csv\
data/import/state.csv\
data/import/county.csv\
data/import/county_msa.csv\
data/import/county_demographics.csv\
data/import/characteristic_type.csv\
data/import/characteristic.csv\
data/import/question.csv\
data/import/response.csv\
data/import/region.csv\
data/import/survey.csv\
data/import/survey_response.csv\
data/import/county_cases.csv\
data/import/actor_type.csv\
data/import/event_type.csv\
data/import/interaction.csv\
data/import/actor.csv\
data/import/acled_event.csv\
data/import/event_actor.csv\
data/import/issue.csv\
data/import/protest_type.csv\
data/import/ccc_actor.csv\
data/import/ccc_event.csv\
data/import/ccc_event_actor.csv\
data/import/ccc_event_issue.csv\
data/import/ccc_event_protest_type.csv;
importcloudsql:
# cleanup build directory
rm -rf build;
mkdir -p build;
# load all DMLs into one SQL File, in order of foreign constraint dependencies
cat\
sql/date/staging-dml.sql\
sql/census_tiger/staging-dml.sql\
sql/census_hhp/staging-dml.sql\
sql/census_demographics/staging-dml.sql\
sql/jhu_covid19/staging-dml.sql\
sql/acled_ccc_events/staging-dml.sql\
> build/importcloud.sql;
mysql\
--host="${MYSQL_HOST}"\
--user="${MYSQL_USER}"\
--password="${MYSQL_PASSWORD}"\
-D covid\
< build/importcloud.sql;
# cleanup
rm -rf build;
createdw: clean
# clean up build directory
rm -rf build;
mkdir -p build;
# load all DDLs into one SQL file, in order of foreign constraint dependencies
cat\
sql/date/dw-ddl.sql\
sql/census_tiger/dw-ddl.sql\
sql/census_hhp/dw-ddl.sql\
sql/census_demographics/dw-ddl.sql\
sql/jhu_covid19/dw-ddl.sql\
sql/acled_ccc_events/dw-ddl.sql\
> build/makedw.sql;
# run SQL file
mysql\
--host="${MYSQL_HOST}"\
--user="${MYSQL_USER}"\
--password="${MYSQL_PASSWORD}"\
-D covid_dw\
< build/makedw.sql;
# cleanup
rm -rf build;
loaddw: clean
# cleanup build directory
rm -rf build;
mkdir -p build;
# load all DMLs into one SQL File, in order of foreign constraint dependencies
cat\
sql/date/dw-dml.sql\
sql/census_tiger/dw-dml.sql\
sql/census_hhp/dw-dml.sql\
sql/census_demographics/dw-dml.sql\
sql/jhu_covid19/dw-dml.sql\
sql/acled_ccc_events/dw-dml.sql\
> build/etldw.sql;
# run SQL file
mysql\
--host="${MYSQL_HOST}"\
--user="${MYSQL_USER}"\
--password="${MYSQL_PASSWORD}"\
-D covid\
< build/etldw.sql;
# cleanup
rm -rf build;