Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Fix broken subscriber data export

Kailash Nadh442dec934108
diff --git a/queries.sql b/queries.sql
index 55fd56e1..f07bfade 100644
--- a/queries.sql
+++ b/queries.sql
@@ -185,42 +185,34 @@ UPDATE subscriber_lists SET status = 'unsubscribed' WHERE
-- privacy
-- name: export-subscriber-data
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
),
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)
WHERE subscriber_lists.subscriber_id = (SELECT id FROM prof)
- GROUP BY subscriber_id
),
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 (
- 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)
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,
- 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
-- queries for segmentation follow.
diff --git a/static/email-templates/subscriber-data.html b/static/email-templates/subscriber-data.html
index 3873abad..afd8fecf 100644
--- a/static/email-templates/subscriber-data.html
+++ b/static/email-templates/subscriber-data.html
@@ -2,7 +2,7 @@
{{ template "header" . }}
<h2>Your data</h2>
<p>
- A copy of all data recorded on you is attached as a file in the JSON format.
+ A copy of all data recorded on you is attached as a file in JSON format.
It can be viewed in a text editor.
</p>
{{ template "footer" }}
diff --git a/static/public/subscriber-data.html b/static/public/subscriber-data.html
index 3873abad..afd8fecf 100644
--- a/static/public/subscriber-data.html
+++ b/static/public/subscriber-data.html
@@ -2,7 +2,7 @@
{{ template "header" . }}
<h2>Your data</h2>
<p>
- A copy of all data recorded on you is attached as a file in the JSON format.
+ A copy of all data recorded on you is attached as a file in JSON format.
It can be viewed in a text editor.
</p>
{{ template "footer" }}