is-coursework/report/data-model/sql/precedents/pr2-notificate-with-settings.sql

12 lines
478 B
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Уведомить с учётом персональных настроек "days_before"
WITH due AS (
SELECT d.id, d.fqdn, d.expires_at, dm.user_id
FROM domain d
JOIN domain_member dm ON dm.domain_id = d.id
WHERE d.expires_at::date = (now() + ($1 || ' days')::interval)::date
)
SELECT u.email, due.fqdn, due.expires_at
FROM due
JOIN expiry_email_pref p ON p.user_id = due.user_id
JOIN app_user u ON u.id = due.user_id
WHERE p.enabled = true AND p.days_before = $1;