|
@@ -185,42 +185,34 @@ UPDATE subscriber_lists SET status = 'unsubscribed' WHERE
|
|
-- privacy
|
|
-- privacy
|
|
-- name: export-subscriber-data
|
|
-- name: export-subscriber-data
|
|
WITH prof AS (
|
|
WITH prof AS (
|
|
- SELECT uuid, email, name, attribs, status, created_at, updated_at FROM subscribers WHERE
|
|
|
|
|
|
+ SELECT id, uuid, email, name, attribs, status, created_at, updated_at FROM subscribers WHERE
|
|
CASE WHEN $1 > 0 THEN id = $1 ELSE uuid = $2 END
|
|
CASE WHEN $1 > 0 THEN id = $1 ELSE uuid = $2 END
|
|
),
|
|
),
|
|
subs AS (
|
|
subs AS (
|
|
- SELECT JSON_AGG(
|
|
|
|
- ROW_TO_JSON(
|
|
|
|
- (SELECT l FROM (
|
|
|
|
- SELECT subscriber_lists.status AS subscription_status,
|
|
|
|
- (CASE WHEN lists.type = 'private' THEN 'Private list' ELSE lists.name END) as name,
|
|
|
|
- lists.type, subscriber_lists.created_at
|
|
|
|
- ) l)
|
|
|
|
- )
|
|
|
|
- ) AS lists FROM lists
|
|
|
|
|
|
+ SELECT subscriber_lists.status AS subscription_status,
|
|
|
|
+ (CASE WHEN lists.type = 'private' THEN 'Private list' ELSE lists.name END) as name,
|
|
|
|
+ lists.type, subscriber_lists.created_at
|
|
|
|
+ FROM lists
|
|
LEFT JOIN subscriber_lists ON (subscriber_lists.list_id = lists.id)
|
|
LEFT JOIN subscriber_lists ON (subscriber_lists.list_id = lists.id)
|
|
WHERE subscriber_lists.subscriber_id = (SELECT id FROM prof)
|
|
WHERE subscriber_lists.subscriber_id = (SELECT id FROM prof)
|
|
- GROUP BY subscriber_id
|
|
|
|
),
|
|
),
|
|
views AS (
|
|
views AS (
|
|
- SELECT JSON_AGG(t) AS views FROM
|
|
|
|
- (SELECT subject as campaign, COUNT(subscriber_id) as views FROM campaign_views
|
|
|
|
- LEFT JOIN campaigns ON (campaigns.id = campaign_views.campaign_id)
|
|
|
|
- WHERE subscriber_id = (SELECT id FROM prof)
|
|
|
|
- GROUP BY campaigns.id ORDER BY id) t
|
|
|
|
|
|
+ SELECT subject as campaign, COUNT(subscriber_id) as views FROM campaign_views
|
|
|
|
+ LEFT JOIN campaigns ON (campaigns.id = campaign_views.campaign_id)
|
|
|
|
+ WHERE subscriber_id = (SELECT id FROM prof)
|
|
|
|
+ GROUP BY campaigns.id ORDER BY id
|
|
),
|
|
),
|
|
clicks AS (
|
|
clicks AS (
|
|
- SELECT JSON_AGG(t) AS views FROM
|
|
|
|
- (SELECT url, COUNT(subscriber_id) as clicks FROM link_clicks
|
|
|
|
|
|
+ SELECT url, COUNT(subscriber_id) as clicks FROM link_clicks
|
|
LEFT JOIN links ON (links.id = link_clicks.link_id)
|
|
LEFT JOIN links ON (links.id = link_clicks.link_id)
|
|
WHERE subscriber_id = (SELECT id FROM prof)
|
|
WHERE subscriber_id = (SELECT id FROM prof)
|
|
- GROUP BY links.id ORDER BY id) t
|
|
|
|
|
|
+ GROUP BY links.id ORDER BY id
|
|
)
|
|
)
|
|
SELECT (SELECT email FROM prof) as email,
|
|
SELECT (SELECT email FROM prof) as email,
|
|
- COALESCE((SELECT JSON_AGG(t) AS profile FROM prof t), '{}') AS profile,
|
|
|
|
- COALESCE((SELECT * FROM subs), '[]') AS subscriptions,
|
|
|
|
- COALESCE((SELECT * FROM views), '[]') AS campaign_views,
|
|
|
|
- COALESCE((SELECT * FROM clicks), '[]') AS link_clicks;
|
|
|
|
|
|
+ COALESCE((SELECT JSON_AGG(t) FROM prof t), '{}') AS profile,
|
|
|
|
+ COALESCE((SELECT JSON_AGG(t) FROM subs t), '[]') AS subscriptions,
|
|
|
|
+ COALESCE((SELECT JSON_AGG(t) FROM views t), '[]') AS campaign_views,
|
|
|
|
+ COALESCE((SELECT JSON_AGG(t) FROM clicks t), '[]') AS link_clicks;
|
|
|
|
|
|
-- Partial and RAW queries used to construct arbitrary subscriber
|
|
-- Partial and RAW queries used to construct arbitrary subscriber
|
|
-- queries for segmentation follow.
|
|
-- queries for segmentation follow.
|