From 04ec44dcef96aa309cfa6a25d4cb40c9ec5bd352 Mon Sep 17 00:00:00 2001 From: Christoph Brand Date: Thu, 20 Jul 2023 18:44:26 +0200 Subject: [PATCH] fix: failing migration Fix an issue in migration which results in the following error message due to wrong and or precedence configuration: ``` panic: runtime error: index out of range [0] with length 0 ``` --- migrations/20221028_fix_heartbeats_time_user_idx.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/migrations/20221028_fix_heartbeats_time_user_idx.go b/migrations/20221028_fix_heartbeats_time_user_idx.go index 506abd5..2a81b27 100644 --- a/migrations/20221028_fix_heartbeats_time_user_idx.go +++ b/migrations/20221028_fix_heartbeats_time_user_idx.go @@ -1,12 +1,13 @@ package migrations import ( + "regexp" + "strings" + "github.com/emvi/logbuch" "github.com/muety/wakapi/config" "github.com/muety/wakapi/models" "gorm.io/gorm" - "regexp" - "strings" ) // due to an error in the model definition, idx_time_user used to only cover 'user_id', but not time column @@ -37,7 +38,7 @@ func init() { } matches := regexp.MustCompile("(?i)\\((.+)\\)$").FindStringSubmatch(ddl) - if len(matches) > 0 && !strings.Contains(matches[0], "`user_id`") || !strings.Contains(matches[0], "`time`") { + if len(matches) > 0 && (!strings.Contains(matches[0], "`user_id`") || !strings.Contains(matches[0], "`time`")) { drop = true } } else {