forked from shaily-omnyagrowth/omnya-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics_setup.sql
More file actions
32 lines (30 loc) · 1.03 KB
/
Copy pathanalytics_setup.sql
File metadata and controls
32 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- Table to store unified post-level analytics for all platforms
create table if not exists video_analytics (
id uuid primary key default gen_random_uuid(),
platform text not null, -- 'tiktok', 'meta', 'youtube'
creator_id uuid references creators(id),
campaign_id uuid references campaigns(id),
submission_id uuid references submissions(id),
video_id text not null, -- Platform specific ID (e.g. IG Media ID, TikTok Video ID)
views bigint default 0,
likes bigint default 0,
comments bigint default 0,
shares bigint default 0,
reach bigint default 0,
saves bigint default 0,
watch_time numeric, -- in seconds
pulled_at timestamptz default now(),
unique(submission_id)
);
-- Enable RLS
alter table video_analytics enable row level security;
-- Policy to allow creators to see their own analytics
create policy "Allow owners to see their own analytics"
on video_analytics for select
using (
exists (
select 1 from creators
where creators.id = video_analytics.creator_id
and creators.user_id = auth.uid()
)
);