From c029df87c4922bed00811e733080723183eeb29c Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Wed, 16 Feb 2022 19:55:47 +0100 Subject: [PATCH] Return default views if database is invalid This affects very few people, and better a quick fix for now. --- settings.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/settings.go b/settings.go index 9f2fc1f6d..e214b393a 100644 --- a/settings.go +++ b/settings.go @@ -296,6 +296,21 @@ func (ss *UserSettings) Scan(v interface{}) error { } } +// This exists as a work-around because a migration set this column wrong >_< +// +// https://github.com/arp242/goatcounter/issues/569#issuecomment-1042013488 +func (w *Widgets) UnmarshalJSON(d []byte) error { + type alias Widgets + ww := alias(*w) + err := json.Unmarshal(d, &ww) + *w = Widgets(ww) + + if err != nil { + *w = defaultWidgets(context.Background()) + } + return nil +} + func (ss *SiteSettings) Defaults(ctx context.Context) { if ss.Campaigns == nil { ss.Campaigns = []string{"utm_campaign", "utm_source", "ref"}