Skip to content

Commit

Permalink
fix: Add security_invoker
Browse files Browse the repository at this point in the history
  • Loading branch information
storm1729 committed Aug 27, 2024
1 parent 82bf026 commit 8b23507
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
6 changes: 5 additions & 1 deletion supabase/migrations/20231218194337_bulk_jobs_info.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
CREATE VIEW bulk_jobs_info AS
DROP VIEW bulk_jobs_info;
CREATE VIEW bulk_jobs_info
WITH
( security_invoker = TRUE )
AS
SELECT
bj.id AS bulk_job_id,
bj.user_id,
Expand Down
44 changes: 29 additions & 15 deletions supabase/migrations/20240116132530_new_sub_and_calls.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,42 @@ WITH
( security_invoker = TRUE )
AS
SELECT
u.id as user_id,
u.id AS user_id,
s.id AS subscription_id,
s.status,
s.current_period_start,
s.current_period_end,
s.cancel_at,
COUNT(c.id) AS number_of_calls,
pro.id as product_id
pro.id AS product_id
FROM
users u
LEFT JOIN
subscriptions s ON u.id = s.user_id AND s.status = 'active'
LEFT JOIN
prices pri ON pri.id = s.price_id
LEFT JOIN
products pro ON pro.id = pri.product_id
LEFT JOIN
calls c ON u.id = c.user_id
public.users u
LEFT JOIN public.subscriptions s ON u.id = s.user_id
AND s.status = 'active'::public.subscription_status
LEFT JOIN public.prices pri ON pri.id = s.price_id
LEFT JOIN public.products pro ON pro.id = pri.product_id
LEFT JOIN public.calls c ON u.id = c.user_id
AND (
(s.current_period_start IS NOT NULL AND s.current_period_end IS NOT NULL AND c.created_at BETWEEN s.current_period_start AND s.current_period_end)
OR
(s.current_period_start IS NULL OR s.current_period_end IS NULL) AND (c.created_at >= NOW() - INTERVAL '1 MONTH')
(
s.current_period_start IS NOT NULL
AND s.current_period_end IS NOT NULL
AND c.created_at >= s.current_period_start
AND c.created_at <= s.current_period_end
)
OR
(
(
s.current_period_start IS NULL
OR s.current_period_end IS NULL
)
AND c.created_at >= (NOW() - '1 mon'::INTERVAL)
)
)
GROUP BY
u.id, s.id, s.status, s.current_period_start, s.current_period_end, s.cancel_at, pro.id;
u.id,
s.id,
s.status,
s.current_period_start,
s.current_period_end,
s.cancel_at,
pro.id;
1 change: 1 addition & 0 deletions supabase/migrations/20240827100258_remove_segment0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP VIEW segment0;

0 comments on commit 8b23507

Please sign in to comment.