Update the connections list query to filter errored connections appropriately. This was a little tricky! The key element though is the FILTER against json_agg. The query I'm targeting roughly looks like this:
SELECT row_to_json(_nango_connections.*) as connection,
row_to_json(end_users.*) as end_user,
_nango_configs.provider,
COALESCE(
json_agg(
json_build_object('type', _nango_active_logs.type, 'log_id', _nango_active_logs.log_id)
) FILTER (WHERE _nango_active_logs.id IS NOT NULL)
, '[]'::json
) as active_logs,
count(_nango_active_logs.id) as active_logs_count
FROM _nango_connections
INNER JOIN _nango_configs ON "_nango_connections"."config_id" = "_nango_configs"."id"
LEFT JOIN end_users ON end_users.id = _nango_connections.end_user_id
LEFT JOIN _nango_active_logs ON _nango_connections.id = _nango_active_logs.connection_id
AND _nango_active_logs.active = true
WHERE _nango_connections.environment_id = 2
AND _nango_connections.deleted = false
GROUP BY _nango_connections.id, end_users.id, _nango_configs.provider
HAVING count(_nango_active_logs.id) = 0
Describe your changes
Update the connections list query to filter errored connections appropriately. This was a little tricky! The key element though is the
FILTER
againstjson_agg
. The query I'm targeting roughly looks like this:Issue ticket number and link
https://linear.app/nango/issue/NAN-2134/bug-with-connection-errors
Checklist before requesting a review (skip if just adding/editing APIs & templates)