Skip to content
Snippets Groups Projects

Added Docker setup for initial database import

Compare and Show latest version
1 file
+ 9
10
Compare changes
  • Side-by-side
  • Inline
+ 9
10
@@ -16,7 +16,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
set -e
printf "\nWelcome to the OpenBuildingMap importer\n\n"
main () {
@@ -29,12 +28,12 @@ main () {
done
# Initiate new or reuse existing database
if ! execute_database_command "\c ${OBM_DATABASE_NAME}"; then
if execute_database_command "\connect ${OBM_DATABASE_NAME}"; then
printf "Reuse existing database: %s\n" "${OBM_DATABASE_NAME}"
else
execute_database_command "CREATE DATABASE ${OBM_DATABASE_NAME};"
add_database_extensions
printf "Initiated new database: %s\n" "${OBM_DATABASE_NAME}"
else
printf "Reuse existing database: %s\n" "${OBM_DATABASE_NAME}"
fi
# Obtain mapping information for database schema
@@ -42,11 +41,11 @@ main () {
# Import OpenStreetMap data if database is empty
database_exists=$(psql --host="${OBM_DATABASE_HOST}" --username="${OBM_DATABASE_USER}" "${OBM_DATABASE_NAME}" --tuples-only --command="SELECT CASE WHEN EXISTS (SELECT FROM pg_tables WHERE schemaname = 'public' AND tablename = 'planet_osm_line' LIMIT 1) THEN 'true' ELSE 'false' end;")
if ! ${database_exists}; then
import_openstreetmap_data
printf "OpenStreetMap data has been imported.\n"
else
if ${database_exists}; then
printf "Assuming already imported database: %s\n" "${OBM_DATABASE_NAME}"
else
import_openstreetmap_data
printf "OpenStreetMap data has been imported.\n"
fi
}
@@ -59,7 +58,7 @@ execute_database_query () {
}
add_database_extensions () {
if psql -h "${OBM_DATABASE_HOST}" -U "${OBM_DATABASE_USER}" -c "\c ${OBM_DATABASE_NAME}"; then
if psql -h "${OBM_DATABASE_HOST}" -U "${OBM_DATABASE_USER}" -c "\connect ${OBM_DATABASE_NAME}"; then
execute_database_query "CREATE EXTENSION postgis;"
printf " postgis extension added to %s database.\n" "${OBM_DATABASE_NAME}"
execute_database_query "CREATE EXTENSION hstore;"
@@ -103,7 +102,7 @@ import_openstreetmap_data () {
--cache-strategy dense \
"${OBM_IMPORT_FILE}"
else
printf "Error: No import file '%s' has been found.\nGood bye.\n" "${OBM_IMPORT_FILE}"
printf "Error: No import file '%s' has been found.\Aborting.\n" "${OBM_IMPORT_FILE}"
exit 1
fi
}
Loading