Fix Edit/Delete on notes saved before properties.id existed
CI / check (push) Successful in 40s
CI / deploy (push) Successful in 12s

The earliest notes (saved before the previous commit added id
tracking) have no properties.id — update/delete target a feature by
that id, so offering Edit/Delete for one without it just 404s
("Could not delete/save the note", the generic fetch-failure alert).

The popup no longer offers Edit/Delete without an id. New
rake gpx:backfill_note_ids assigns one to any pre-existing Note
feature missing it, so already-saved notes become editable again too
— run once against wherever data/gpx actually lives (e.g. inside the
deployed container).
This commit is contained in:
randy committed 2026-09-09 12:58:19 +02:00
1 parent b0576f3725
commit 2a22906a68
3 files changed
+35 -1

No files matched your search

+30
View File
@@ -23,3 +23,33 @@ namespace :overpass do
puts "Wrote #{geojson["features"].size} POIs to #{args[:out]}"
end
end
namespace :gpx do
desc "Backfill properties.id on Note-category features saved before edit/delete (and its id targeting) existed"
task :backfill_note_ids do
require "json"
require "securerandom"
data_dir = ENV.fetch("MAPTOOL_DATA_DIR") { File.join(__dir__, "data") }
count = 0
Dir.glob(File.join(data_dir, "gpx", "**", "*.geojson")).each do |file|
# ".gpx.geojson"/".fit.geojson" are GpxStore's own cache sidecars for
# an uploaded GPX/FIT (regenerated from the source on demand, see
# GpxStore#geojson) — never hand-drawn notes, not worth touching.
next if file.end_with?(".gpx.geojson", ".fit.geojson")
collection = JSON.parse(File.read(file))
changed = false
(collection["features"] || []).each do |feature|
properties = (feature["properties"] ||= {})
next unless properties["category"] == "Note" && !properties["id"]
properties["id"] = SecureRandom.uuid
changed = true
count += 1
end
File.write(file, JSON.generate(collection)) if changed
end
puts "Backfilled #{count} note id(s)"
end
end