Skip to content

Commit 7932958

Browse files
fix: scope config query to support postgresql and mysql (#8327)
1 parent 24ca478 commit 7932958

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

backend/helpers/srvhelper/scope_config_service_helper.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,17 @@ func (scopeConfigSrv *ScopeConfigSrvHelper[C, S, SC]) GetProjectsByScopeConfig(p
7777
ScopeId string
7878
}
7979
scopeTable := (*s).TableName()
80+
// Postgres fails as scope_id is a varchar and theOtherPk can be an integer in some cases
81+
join := fmt.Sprintf("LEFT JOIN %s ON (%s.connection_id = bps.connection_id AND %s = bps.scope_id)", scopeTable, scopeTable, theOtherPk)
82+
if scopeConfigSrv.db.Dialect() == "postgres" {
83+
join = fmt.Sprintf("LEFT JOIN %s ON (%s.connection_id = bps.connection_id AND CAST(%s AS varchar) = bps.scope_id)", scopeTable, scopeTable, theOtherPk)
84+
}
8085
errors.Must(scopeConfigSrv.db.All(
8186
&bpss,
8287
dal.Select(fmt.Sprintf("bp.id AS blueprint_id, bp.project_name, bps.scope_id, %s.*", scopeTable)),
8388
dal.From("_devlake_blueprint_scopes bps"),
8489
dal.Join("LEFT JOIN _devlake_blueprints bp ON (bp.id = bps.blueprint_id)"),
85-
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)),
90+
dal.Join(join),
8691
dal.Where("bps.plugin_name = ? AND bps.connection_id = ?", pluginName, (*scopeConfig).ScopeConfigConnectionId()),
8792
))
8893
projectScopeMap := make(map[string]*models.ProjectScope)

0 commit comments

Comments
 (0)