-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimportdb
executable file
·48 lines (38 loc) · 1.14 KB
/
importdb
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
#!/bin/bash
# $ ./importdb ri 2020-12-28T19_23Z.sql
# $ ./importdb ri
if [ ! $2 ] ; then
echo
echo \* This updates the postgres database for the local copies of the state databases,
echo \* which are used by \$ yarn serve:ri and \$ yarn serve:oh.
echo \*
echo \* First, download the state database to examples/ri/sql and unzip it.
echo \*
echo \* Get the filename with:
echo \* \$ ls -t examples/ri/sql
echo \*
echo \* then run this:
echo \* \$ ./importdb ri 2020-12-28T19_23Z.sql \*use the sql file you just downloaded\*
echo
exit 1
fi
dbname=${1}
dbuser=postgres
exampleDir=examples
infile=${2}
inpath=./${exampleDir}/${1}/sql/${infile}
outfile=${2//sql/clean.sql}
outpath=./${exampleDir}/${1}/sql/${outfile}
dropdb ${dbname}
createdb --owner=${dbuser} ${dbname}
# rm uploads/*
echo Working...
# cares_reporter_bi26_user is from ri
# cares_reporter_a2n0_user is from oh
junk="cares_reporter_bi26_user|cares_reporter_a2n0_user|\
tiger|topology|geometry|geography|spatial|raster|pg_similarity|postgis"
# echo ${junk}
egrep -v ${junk} ${inpath}\
| pcre2grep -M -v '(\n\n\\\.)'\
> ${outpath}
psql ${dbname} ${dbuser} < ${outpath}