Skip to content

Commit 6881e3e

Browse files
author
Rub21
committed
Fix import pbf fiel to db-api
1 parent 5c878c1 commit 6881e3e

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

images/populate-apidb/start.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env bash
2+
export VOLUME_DIR=/mnt/data
3+
export PGPASSWORD=$POSTGRES_PASSWORD
24

35
# OSMOSIS tuning: https://wiki.openstreetmap.org/wiki/Osmosis/Tuning,https://lists.openstreetmap.org/pipermail/talk/2012-October/064771.html
46
if [ -z "$MEMORY_JAVACMD_OPTIONS" ]; then
@@ -7,14 +9,18 @@ else
79
memory="${MEMORY_JAVACMD_OPTIONS//i}"
810
echo JAVACMD_OPTIONS=\"-server -Xmx$memory\" > ~/.osmosis
911
fi
12+
1013
# Get the data
11-
wget $URL_FILE_TO_IMPORT
1214
file=$(basename $URL_FILE_TO_IMPORT)
15+
osmFile=$VOLUME_DIR/$file
16+
[ ! -f $osmFile ] && wget $URL_FILE_TO_IMPORT
1317

1418
function importData () {
19+
# This is using a osmosis 0.47. TODO: test with osmosis 0.48, and remove the following line
20+
psql -U $POSTGRES_USER -h $POSTGRES_HOST -d $POSTGRES_DB -c "ALTER TABLE users ADD COLUMN nearby VARCHAR;"
1521
# In case the import file is a PBF
16-
if [ ${file: -4} == ".pbf" ]; then
17-
pbfFile=$file
22+
if [ ${osmFile: -4} == ".pbf" ]; then
23+
pbfFile=$osmFile
1824
echo "Importing $pbfFile ..."
1925
osmosis --read-pbf \
2026
file=$pbfFile\
@@ -23,12 +29,13 @@ function importData () {
2329
database=$POSTGRES_DB \
2430
user=$POSTGRES_USER \
2531
password=$POSTGRES_PASSWORD \
32+
allowIncorrectSchemaVersion=yes \
2633
validateSchemaVersion=no
2734
else
2835
# In case the file is .osm
2936
# Extract the osm file
30-
bzip2 -d $file
31-
osmFile=${file%.*}
37+
bzip2 -d $osmFile
38+
osmFile=${osmFile%.*}
3239
echo "Importing $osmFile ..."
3340
osmosis --read-xml \
3441
file=$osmFile \
@@ -39,6 +46,13 @@ function importData () {
3946
password=$POSTGRES_PASSWORD \
4047
validateSchemaVersion=no
4148
fi
49+
# Run required fixes in DB
50+
psql -U $POSTGRES_USER -h $POSTGRES_HOST -d $POSTGRES_DB -c "select setval('current_nodes_id_seq', (select max(node_id) from nodes));"
51+
psql -U $POSTGRES_USER -h $POSTGRES_HOST -d $POSTGRES_DB -c "select setval('current_ways_id_seq', (select max(way_id) from ways));"
52+
psql -U $POSTGRES_USER -h $POSTGRES_HOST -d $POSTGRES_DB -c "select setval('current_relations_id_seq', (select max(relation_id) from relations));"
53+
# psql -U $POSTGRES_USER -h $POSTGRES_HOST -d $POSTGRES_DB -c "select setval('users_id_seq', (select max(id) from users));"
54+
# psql -U $POSTGRES_USER -h $POSTGRES_HOST -d $POSTGRES_DB -c "select setval('changesets_id_seq', (select max(id) from changesets));"
55+
4256
}
4357

4458
flag=true

0 commit comments

Comments
 (0)