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

klesh 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 793295807 fix: scope config query to support postgresql and mysql 
(#8327)
793295807 is described below

commit 79329580710751a59d36f9147d53947fcf55239e
Author: Kostas Petrakis <[email protected]>
AuthorDate: Mon Mar 10 07:41:24 2025 +0100

    fix: scope config query to support postgresql and mysql (#8327)
---
 backend/helpers/srvhelper/scope_config_service_helper.go | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/backend/helpers/srvhelper/scope_config_service_helper.go 
b/backend/helpers/srvhelper/scope_config_service_helper.go
index 7a93492a6..9964f3f92 100644
--- a/backend/helpers/srvhelper/scope_config_service_helper.go
+++ b/backend/helpers/srvhelper/scope_config_service_helper.go
@@ -77,12 +77,17 @@ func (scopeConfigSrv *ScopeConfigSrvHelper[C, S, SC]) 
GetProjectsByScopeConfig(p
                ScopeId     string
        }
        scopeTable := (*s).TableName()
+       // Postgres fails as scope_id is a varchar and theOtherPk can be an 
integer in some cases
+       join := fmt.Sprintf("LEFT JOIN %s ON (%s.connection_id = 
bps.connection_id AND %s = bps.scope_id)", scopeTable, scopeTable, theOtherPk)
+       if scopeConfigSrv.db.Dialect() == "postgres" {
+               join = fmt.Sprintf("LEFT JOIN %s ON (%s.connection_id = 
bps.connection_id AND CAST(%s AS varchar) = bps.scope_id)", scopeTable, 
scopeTable, theOtherPk)
+       }
        errors.Must(scopeConfigSrv.db.All(
                &bpss,
                dal.Select(fmt.Sprintf("bp.id AS blueprint_id, bp.project_name, 
bps.scope_id, %s.*", scopeTable)),
                dal.From("_devlake_blueprint_scopes bps"),
                dal.Join("LEFT JOIN _devlake_blueprints bp ON (bp.id = 
bps.blueprint_id)"),
-               dal.Join(fmt.Sprintf("LEFT JOIN %s ON (%s.connection_id = 
bps.connection_id AND cast(%s as varchar) = bps.scope_id)", scopeTable, 
scopeTable, theOtherPk)),
+               dal.Join(join),
                dal.Where("bps.plugin_name = ? AND bps.connection_id = ?", 
pluginName, (*scopeConfig).ScopeConfigConnectionId()),
        ))
        projectScopeMap := make(map[string]*models.ProjectScope)

Reply via email to