Team Ai
Apppublic

Hans-R-D/Auth.Nexus

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
init_supabase_sql.txt45 linesDownload Raw Back to root
1-- Users table2CREATE TABLE IF NOT EXISTS public.users (3    user_id varchar(16) PRIMARY KEY, -- Use BIGINT for larger integer values4    username TEXT UNIQUE NOT NULL,5    password TEXT NOT NULL,6    email TEXT,7    date_joined TIMESTAMP WITH TIME ZONE NOT NULL,8    access_level TEXT NOT NULL9);10 11-- Sessions table with composite primary key (user_id, token)12create table if not exists public.sessions (13    user_id varchar(16) references public.users(user_id),14    token text not null,15    expires timestamp with time zone not null,16    device text not null,17    primary key (user_id, token)  -- Composite primary key18);19 20-- Create indexes for better performance21create index if not exists idx_users_username on public.users(username);22create index if not exists idx_users_user_id on public.users(user_id);23create index if not exists idx_sessions_user_id on public.sessions(user_id);24create index if not exists idx_sessions_token on public.sessions(token);25 26-- Set up Row Level Security (RLS)27alter table public.users enable row level security;28alter table public.sessions enable row level security;29 30-- Create policies31create policy "Enable read access for all users"32    on public.users for select33    using (true);34 35create policy "Enable insert for authenticated users only"36    on public.users for insert37    with check (true);38 39create policy "Enable update for authenticated users"40    on public.users for update41    using (true);42 43create policy "Enable all access for sessions"44    on public.sessions for all45    using (true);