forked from hopcity/cityscrape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-ddl-generation.sh
executable file
·63 lines (50 loc) · 1.47 KB
/
run-ddl-generation.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
#!/bin/bash
CONFIGFILE="config/cityscrape-config.sh"
. $CONFIGFILE
echo "Running Cityscrape PostgreSQL Ingest"
pushd $WORKDIR
echo "Unzipping files..."
zip_files=$(echo `ls *.zip 2>/dev/null`)
if [ -z "$zip_files" ]; then
echo "No *.zip files found, skipping unzip..."
else
for zip_file in $zip_files;
do
unzip -o $zip_file
done
echo "Unzip complete"
fi
shp_files=$(echo `ls *.shp 2>/dev/null`)
if [ -z "$shp_files" ]; then
echo "No *.shp files found, skipping ogr2ogr..."
else
for shp_file in $shp_files;
do
echo `ls $shp_file`
# ogr2ogr -overwrite -progress -skipfailures -f "PostgreSQL" PG:"host=localhost user=postgres dbname=city" $shp_file
done
fi
pushd $DDL_FILES
echo "Building ddl sql files now..."
mdb_files=$(echo `ls *.mdb 2>/dev/null`)
if [ -z "$mdb_files" ]; then
echo "No *.mdb files found, exiting..."
else
for mdb_file in $mdb_files
do
echo "Extracting tables from $mdb_file"
ddl_file=$mdb_file$DDL_FILE_SUFFIX
mdb-schema $mdb_file | sed 's/Char/Varchar/g' | sed 's/Postgres_Unknown 0x0c/text/g' > "$ddl_file"
tables=$(echo -en $(mdb-schema $mdb_file postgres | grep "CREATE TABLE IF NOT EXISTS" | awk '{ print $3 }' | sed -e 's/"//g');)
if [ -z "$tables" ]
then
echo "No tables found, skipping table ddl generation."
else
for table in $tables
do
echo $table > "$table$DDL_FILE_SUFFIX"
done
fi
done
fi
popd