diff --git a/images/tiler-imposm/start.sh b/images/tiler-imposm/start.sh index 33f17742..965b9789 100755 --- a/images/tiler-imposm/start.sh +++ b/images/tiler-imposm/start.sh @@ -233,9 +233,38 @@ function monitorImposmErrors() { done } +function importMissingLayers() { + # Layers added after the initial import have no table yet and "imposm run" fails on them. + local missing_layers + missing_layers=$(psql "$PG_CONNECTION" -At -c "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';" | python3 -c ' +import glob, json, sys +existing = set(sys.stdin.read().split()) +mapped = json.load(open("./config/imposm3.json"))["tables"] +layers = [p.split("/")[-1][:-5] for p in sorted(glob.glob("./config/layers/*.json")) + if any(t in mapped and "osm_" + t not in existing for t in json.load(open(p))["tables"])] +print(" ".join(layers))') + + if [ -n "$missing_layers" ]; then + log_message "Importing missing layers: $missing_layers" + getData + if ! ./scripts/reimport_layer.sh $missing_layers; then + log_message "ERROR: Failed to import missing layers: $missing_layers" + exit 1 + fi + touch "$WORKDIR/mviews_pending" + fi + + # The marker survives a restart in the middle of create_mviews.sh, so the views get retried. + if [ -f "$WORKDIR/mviews_pending" ] && [ "$RECREATE_MVIEWS_ON_UPDATE" != "true" ]; then + ./scripts/create_mviews.sh && rm -f "$WORKDIR/mviews_pending" + fi +} + function updateData() { log_message "Starting database update process..." + importMissingLayers + # Step 0: Recreate materialized views if RECREATE_MVIEWS_ON_UPDATE is enabled if [ "$RECREATE_MVIEWS_ON_UPDATE" = "true" ]; then log_message "Recreating materialized views before update..." diff --git a/values.k3s.production.template.yaml b/values.k3s.production.template.yaml index 7684dbbc..063fca39 100644 --- a/values.k3s.production.template.yaml +++ b/values.k3s.production.template.yaml @@ -48,7 +48,7 @@ osm-seed: mountPath: /var/lib/postgresql/data subPath: postgresql-data staticHostPath: true - localVolumeHostPath: /mnt/tiler-db-data-v6 + localVolumeHostPath: /mnt/tiler-db-data-v7 resources: enabled: false postgresqlConfig: @@ -160,7 +160,7 @@ osm-seed: accessMode: ReadWriteOnce mountPath: /mnt/data staticHostPath: true - localVolumeHostPath: /mnt/tiler-imposm-data-v6 + localVolumeHostPath: /mnt/tiler-imposm-data-v7 resources: enabled: true nodeSelector: