This is an automated email from the ASF dual-hosted git repository.

zky pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 63263ca8c fix: normalize_bp_settings throws error (#6249)
63263ca8c is described below

commit 63263ca8cf9d3ea916cbe343367968a2db84b44b
Author: Klesh Wong <[email protected]>
AuthorDate: Mon Oct 16 17:38:25 2023 +0800

    fix: normalize_bp_settings throws error (#6249)
    
    * fix: normalize_bp_settings throws error
    
    * fix: pg ci
---
 .../core/models/migrationscripts/20230829_normalize_bp_settings.go  | 6 +++++-
 backend/helpers/migrationhelper/migrationhelper.go                  | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git 
a/backend/core/models/migrationscripts/20230829_normalize_bp_settings.go 
b/backend/core/models/migrationscripts/20230829_normalize_bp_settings.go
index 881dcb9bb..5878af126 100644
--- a/backend/core/models/migrationscripts/20230829_normalize_bp_settings.go
+++ b/backend/core/models/migrationscripts/20230829_normalize_bp_settings.go
@@ -74,7 +74,8 @@ func (script *normalizeBpSettings) Up(basicRes 
context.BasicRes) errors.Error {
        }
        db := basicRes.GetDal()
        bp := &blueprint20230829{}
-       cursor := errors.Must1(db.Cursor(dal.From("_devlake_blueprints")))
+       _ = db.First(bp)
+       cursor := errors.Must1(db.Cursor(dal.From("_devlake_blueprints"), 
dal.Where("mode = ?", "NORMAL")))
        defer cursor.Close()
 
        for cursor.Next() {
@@ -82,6 +83,9 @@ func (script *normalizeBpSettings) Up(basicRes 
context.BasicRes) errors.Error {
                errors.Must(db.Fetch(cursor, bp))
                // decrypt and unmarshal settings
                settingsJson := errors.Must1(plugin.Decrypt(encKey, 
bp.Settings))
+               if settingsJson == "" {
+                       continue
+               }
                settings := &blueprintSettings20230829{}
                errors.Must(json.Unmarshal([]byte(settingsJson), settings))
                // update bp fields
diff --git a/backend/helpers/migrationhelper/migrationhelper.go 
b/backend/helpers/migrationhelper/migrationhelper.go
index c1247e469..b1215ac3b 100644
--- a/backend/helpers/migrationhelper/migrationhelper.go
+++ b/backend/helpers/migrationhelper/migrationhelper.go
@@ -39,7 +39,7 @@ func AutoMigrateTables(basicRes context.BasicRes, dst 
...interface{}) errors.Err
                if err != nil {
                        return err
                }
-               _ = db.All(entity)
+               _ = db.First(entity)
        }
        return nil
 }

Reply via email to