forked from shaily-omnyagrowth/omnya-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_setup.sql
More file actions
147 lines (136 loc) · 4.88 KB
/
Copy pathdatabase_setup.sql
File metadata and controls
147 lines (136 loc) · 4.88 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
-- Run this in Supabase SQL Editor to set up your database
-- 1. User profiles (links auth users to roles)
create table if not exists user_profiles (
id uuid references auth.users primary key,
email text unique not null,
full_name text,
role text default 'pending' check (role in ('creator','am','account_manager','owner','pending','denied')),
created_at timestamptz default now()
);
-- 2. Account Managers
create table if not exists account_managers (
id uuid primary key default gen_random_uuid(),
user_id uuid references auth.users,
name text not null,
email text unique not null,
created_at timestamptz default now()
);
-- 3. Creators
create table if not exists creators (
id uuid primary key default gen_random_uuid(),
user_id uuid references auth.users,
name text not null,
email text unique not null,
tiktok_handle text,
instagram_handle text,
status text default 'Active',
weekly_rate numeric default 150,
videos_per_week integer default 15,
payment_status text default 'Current',
am_id uuid references account_managers,
created_at timestamptz default now()
);
-- 4. Clients
create table if not exists clients (
id uuid primary key default gen_random_uuid(),
name text not null,
deal_type text default 'Monthly Retainer',
videos_per_month integer default 20,
budget numeric default 0,
status text default 'Active',
contact_name text,
contact_email text,
contact_phone text,
contract_terms text,
drive_link text,
am_id uuid references account_managers,
created_at timestamptz default now()
);
-- 5. Campaigns
create table if not exists campaigns (
id uuid primary key default gen_random_uuid(),
name text not null,
client_id uuid references clients,
description text,
format text default 'TikTok',
videos_needed integer default 10,
pay_per_video numeric default 10,
deadline date,
status text default 'Open',
application_type text default 'Open Application',
assigned_creators uuid[] default '{}',
created_at timestamptz default now()
);
-- 6. Submissions
create table if not exists submissions (
id uuid primary key default gen_random_uuid(),
creator_id uuid references creators,
campaign_id uuid references campaigns,
submission_type text default 'Concept',
concept_link text,
concept_status text default 'Pending',
posted_link text,
final_status text,
platform text default 'TikTok',
feedback text,
approved_date date,
views_24h bigint, views_72h bigint, views_1w bigint, views_2w bigint, views_1m bigint,
likes bigint, comments bigint, shares bigint, saves bigint,
payment_status text default 'Unpaid',
ai_insights jsonb,
created_at timestamptz default now()
);
-- 7. Payments
create table if not exists payments (
id uuid primary key default gen_random_uuid(),
creator_id uuid references creators,
campaign_id uuid references campaigns,
submission_id uuid references submissions,
week_ending date,
videos_approved integer default 0,
amount_owed numeric default 0,
status text default 'Pending',
payment_method text,
paid_date date,
created_at timestamptz default now()
);
-- 8. Messages (Forum)
create table if not exists messages (
id uuid primary key default gen_random_uuid(),
campaign_id uuid references campaigns,
user_id uuid,
sender_name text,
content text,
reactions jsonb default '{}',
is_pinned boolean default false,
created_at timestamptz default now()
);
-- Enable Row Level Security (allow all for development)
alter table user_profiles enable row level security;
alter table creators enable row level security;
alter table clients enable row level security;
alter table campaigns enable row level security;
alter table submissions enable row level security;
alter table payments enable row level security;
alter table account_managers enable row level security;
alter table messages enable row level security;
-- Policies
do $$
begin
drop policy if exists "Allow all" on user_profiles;
drop policy if exists "Allow all" on creators;
drop policy if exists "Allow all" on clients;
drop policy if exists "Allow all" on campaigns;
drop policy if exists "Allow all" on submissions;
drop policy if exists "Allow all" on payments;
drop policy if exists "Allow all" on account_managers;
drop policy if exists "Allow all" on messages;
end $$;
create policy "Allow all" on user_profiles for all using (true) with check (true);
create policy "Allow all" on creators for all using (true) with check (true);
create policy "Allow all" on clients for all using (true) with check (true);
create policy "Allow all" on campaigns for all using (true) with check (true);
create policy "Allow all" on submissions for all using (true) with check (true);
create policy "Allow all" on payments for all using (true) with check (true);
create policy "Allow all" on account_managers for all using (true) with check (true);
create policy "Allow all" on messages for all using (true) with check (true);