-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase_schema.sql
More file actions
77 lines (69 loc) · 3.92 KB
/
Copy pathsupabase_schema.sql
File metadata and controls
77 lines (69 loc) · 3.92 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
-- Create a table for storing user holdings (OPTIONAL - only used if Cloud Sync is enabled)
-- In Hybrid Model, this is mostly unused by default
create table if not exists holdings (
id uuid default gen_random_uuid() primary key,
user_id uuid references auth.users not null,
symbol text not null,
name text,
asset_type text not null,
quantity numeric not null check (quantity >= 0),
buy_price numeric check (buy_price >= 0),
created_at timestamp with time zone default timezone('utc'::text, now()) not null
);
-- User Settings (Risk Profile, Max Caps)
create table if not exists user_settings (
user_id uuid references auth.users primary key,
risk_profile text default 'MODERATE', -- 'CONSERVATIVE', 'MODERATE', 'AGGRESSIVE'
max_sector_cap numeric default 25.0,
max_stock_cap numeric default 15.0,
updated_at timestamp with time zone default timezone('utc'::text, now())
);
-- Risk Reports (Metadata only - Privacy Safe)
create table if not exists risk_reports (
id uuid default gen_random_uuid() primary key,
user_id uuid references auth.users not null,
risk_score numeric,
volatility_score numeric,
diversification_score numeric,
created_at timestamp with time zone default timezone('utc'::text, now()) not null
);
-- Enable RLS
alter table holdings enable row level security;
alter table user_settings enable row level security;
alter table risk_reports enable row level security;
-- Policies for Holdings
create policy "Users can view their own holdings" on holdings for select using (auth.uid() = user_id);
create policy "Users can insert their own holdings" on holdings for insert with check (auth.uid() = user_id);
create policy "Users can update their own holdings" on holdings for update using (auth.uid() = user_id);
create policy "Users can delete their own holdings" on holdings for delete using (auth.uid() = user_id);
-- Policies for User Settings
create policy "Users can view their own settings" on user_settings for select using (auth.uid() = user_id);
create policy "Users can update their own settings" on user_settings for update using (auth.uid() = user_id);
create policy "Users can insert their own settings" on user_settings for insert with check (auth.uid() = user_id);
-- Policies for Risk Reports
create policy "Users can view their own reports" on risk_reports for select using (auth.uid() = user_id);
create policy "Users can insert their own reports" on risk_reports for insert with check (auth.uid() = user_id);