-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase-schema.sql
More file actions
31 lines (27 loc) · 1018 Bytes
/
supabase-schema.sql
File metadata and controls
31 lines (27 loc) · 1018 Bytes
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
-- PROFILES table (required for auth)
create table profiles (
id uuid references auth.users(id) on delete cascade primary key,
email text unique not null,
first_name text,
last_name text,
employee_id text unique,
role text default 'USER',
designation_id uuid,
band_id uuid,
office_location_id uuid,
reporting_manager uuid references profiles(id),
joining_date date,
is_active boolean default true,
created_at timestamptz default now(),
updated_at timestamptz default now()
);
-- Enable RLS
alter table profiles enable row level security;
-- Users can read their own profile
create policy "Users can view own profile" on profiles for select using (auth.uid() = id);
-- Users can update their own profile
create policy "Users can update own profile" on profiles for update using (auth.uid() = id);
-- Admins can view all profiles
create policy "Admins can view all profiles" on profiles for select using (
exists (select 1 from profiles where id = auth.uid() and role = 'SUPERADMIN')
);