Skip to content

Commit

Permalink
Add name to ignored_renewals
Browse files Browse the repository at this point in the history
  • Loading branch information
maximbaz committed Nov 24, 2024
1 parent f3a7ed8 commit 84f9842
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 12 additions & 0 deletions db/migrations/20241123140526_add-ignored-renewals-view.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ create view ignored_renewals as
with last_charge as (
select distinct on (p.id)
p.id,
p.name,
p.email,
d.amount,
d.recipient,
Expand Down Expand Up @@ -46,8 +47,18 @@ last_payment_by_email as (
p.email,
d.recipient,
c.created_at desc
),
email_to_name as (
select distinct on (email)
name,
email
from
donor_with_contact_info p
where
name is not null
)
select
coalesce(lc.name, en.name) as name,
lc.email,
lc.amount,
lc.recipient,
Expand All @@ -57,6 +68,7 @@ from
join never_activated na on lc.id = na.id
left join last_payment_by_email lp on lc.email = lp.email
and lc.recipient = lp.recipient
left join email_to_name en on lc.email = en.email
where
lc.status = 'error'
and (lp.created_at is null
Expand Down
12 changes: 10 additions & 2 deletions db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,7 @@ CREATE VIEW giveffektivt.gavebrev_checkins_to_create AS
CREATE VIEW giveffektivt.ignored_renewals AS
WITH last_charge AS (
SELECT DISTINCT ON (p.id) p.id,
p.name,
p.email,
d.amount,
d.recipient,
Expand All @@ -1192,14 +1193,21 @@ CREATE VIEW giveffektivt.ignored_renewals AS
JOIN giveffektivt.charge c ON ((d.id = c.donation_id)))
WHERE (c.status = 'charged'::giveffektivt.charge_status)
ORDER BY p.email, d.recipient, c.created_at DESC
), email_to_name AS (
SELECT DISTINCT ON (p.email) p.name,
p.email
FROM giveffektivt.donor_with_contact_info p
WHERE (p.name IS NOT NULL)
)
SELECT lc.email,
SELECT COALESCE(lc.name, en.name) AS name,
lc.email,
lc.amount,
lc.recipient,
((now())::date - (na.created_at)::date) AS days_ago
FROM ((last_charge lc
FROM (((last_charge lc
JOIN never_activated na ON ((lc.id = na.id)))
LEFT JOIN last_payment_by_email lp ON (((lc.email = lp.email) AND (lc.recipient = lp.recipient))))
LEFT JOIN email_to_name en ON ((lc.email = en.email)))
WHERE ((lc.status = 'error'::giveffektivt.charge_status) AND ((lp.created_at IS NULL) OR (lp.created_at < lc.created_at)))
ORDER BY na.created_at;

Expand Down

0 comments on commit 84f9842

Please sign in to comment.