From 6803c205a97f8770389b0ad76edeff9d38ff71a5 Mon Sep 17 00:00:00 2001 From: Storm Date: Thu, 26 Dec 2024 19:42:16 +0100 Subject: [PATCH] feat: Add unknown count to commercial analytics --- .../20241226184126_add_unknown_count.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 supabase/migrations/20241226184126_add_unknown_count.sql diff --git a/supabase/migrations/20241226184126_add_unknown_count.sql b/supabase/migrations/20241226184126_add_unknown_count.sql new file mode 100644 index 0000000..d6dc8bc --- /dev/null +++ b/supabase/migrations/20241226184126_add_unknown_count.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE VIEW analytics_commercial_license_users_past_month +WITH (security_invoker = on) AS +SELECT + u.id AS user_id, + u.email, + u.created_at AS registration_date, + COUNT(c.id) AS call_count, + SUM(CASE WHEN c.is_reachable = 'unknown' THEN 1 ELSE 0 END) AS unknown_email_count +FROM auth.users u +JOIN calls c ON u.id = c.user_id +WHERE c.endpoint = '/v1/commercial_license_trial' + AND c.created_at >= NOW() - INTERVAL '1 month' +GROUP BY u.id, u.email, u.created_at +ORDER BY call_count DESC; \ No newline at end of file