| Actor | Fragment | Worker | State |
|---|---|---|---|
| 745237 | 63078 | 51 | running |
| 745238 | 63078 | 51 | running |
| 745239 | 63082 | 51 | running |
| 745240 | 63082 | 51 | running |
| 745314 | 63072 | 51 | running |
| 745315 | 63072 | 51 | running |
| 745316 | 63073 | 51 | running |
| 745317 | 63073 | 51 | running |
| 745326 | 63074 | 51 | running |
| 745327 | 63074 | 51 | running |
| 745328 | 63075 | 51 | running |
| 745329 | 63075 | 51 | running |
CREATE MATERIALIZED VIEW alinma_bff.portfolio_owners_mv AS
WITH owner_rows AS (
SELECT
cp.portfolio_id,
c.id AS owner_id,
c.display_name,
c.local_display_name,
c.preferred_name,
cp.owner_type
FROM olap.clients_portfolios_dm AS cp
JOIN olap.clients_dm AS c
ON c.id = cp.client_id AND c.closing_date IS NULL
WHERE
cp.disabled_at IS NULL AND cp.effective_end_date IS NULL
UNION ALL
SELECT
ptp.portfolio_id,
p.id AS owner_id,
p.display_name,
CAST(NULL AS VARCHAR) AS local_display_name,
CAST(NULL AS VARCHAR) AS preferred_name,
CASE
WHEN ptp.involvement_type = 'PORTFOLIO_HOLDER'
THEN 'PRIMARY'
ELSE 'SECONDARY'
END AS owner_type
FROM alinma_bff.party_active_portfolio_involvements_mv AS ptp
JOIN party.parties AS p
ON p.id = ptp.party_id AND p.disabled_at IS NULL
)
SELECT
portfolio_id,
JSONB_AGG(
JSONB_BUILD_OBJECT(
'id',
owner_id,
'displayName',
display_name,
'localDisplayName',
local_display_name,
'preferredName',
preferred_name,
'ownerType',
owner_type
) ORDER BY owner_id
) AS owners,
CAST(COUNT(*) AS INT) AS owner_count
FROM owner_rows
GROUP BY
portfolio_id