From b304e9975a993815f22d2bb4ab1e09f9fee0210d Mon Sep 17 00:00:00 2001 From: slothful-vassal <89943360+slothful-vassal@users.noreply.github.com> Date: Thu, 4 Jun 2026 17:47:04 +0200 Subject: [PATCH] fix polyline db field size (#1047) --- .../1778583700_updated_trails_polyline_max.go | 36 +++++++++++++++++++ db/util/polyline.go | 6 ++++ 2 files changed, 42 insertions(+) create mode 100644 db/migrations/1778583700_updated_trails_polyline_max.go diff --git a/db/migrations/1778583700_updated_trails_polyline_max.go b/db/migrations/1778583700_updated_trails_polyline_max.go new file mode 100644 index 00000000..dc077eb4 --- /dev/null +++ b/db/migrations/1778583700_updated_trails_polyline_max.go @@ -0,0 +1,36 @@ +package migrations + +import ( + "pocketbase/util" + + "github.com/pocketbase/pocketbase/core" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("e864strfxo14pm4") + if err != nil { + return err + } + + field, ok := collection.Fields.GetByName("polyline").(*core.TextField) + if ok { + field.Max = util.PolylineMaxLength + } + + return app.Save(collection) + }, func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("e864strfxo14pm4") + if err != nil { + return err + } + + field, ok := collection.Fields.GetByName("polyline").(*core.TextField) + if ok { + field.Max = 0 + } + + return app.Save(collection) + }) +} diff --git a/db/util/polyline.go b/db/util/polyline.go index 4b782909..291a740e 100644 --- a/db/util/polyline.go +++ b/db/util/polyline.go @@ -10,6 +10,8 @@ import ( "github.com/twpayne/go-polyline" ) +const PolylineMaxLength = 5 * 1024 * 1024 + func ComputePolyline(app core.App, r *core.Record) (string, error) { gpxPath := r.GetString("gpx") if len(gpxPath) == 0 { @@ -56,6 +58,10 @@ func SavePolyline(app core.App, r *core.Record) error { if err != nil { return err } + // Encoded polylines are ASCII-only, so byte length matches character length. + if len(encoded) > PolylineMaxLength { + return fmt.Errorf("polyline exceeds maximum length of %d characters", PolylineMaxLength) + } r.Set("polyline", encoded) if err := app.UnsafeWithoutHooks().Save(r); err != nil { return fmt.Errorf("save trail polyline: %w", err)