Skip to Content

Database

Supabase provides a PostgreSQL database. This guide covers creating tables and setting up security policies.

Create Tables

Go to SQL Editor in your Supabase dashboard and run these queries.

User Profiles Table

Stores user preferences and subscription data:

create table user_profiles ( id uuid default gen_random_uuid() primary key, user_id text not null, theme text default 'light', notifications_enabled boolean default true, subscription_plan text, subscription_status text, will_renew boolean default false, created_at timestamp with time zone default now() not null, updated_at timestamp with time zone default now() not null );

Expo Push Tokens Table

Stores push notification tokens:

create table expo_push_tokens ( id uuid default gen_random_uuid() primary key, token text not null unique, user_id text, revenuecat_id text, created_at timestamp with time zone default now() not null );

Row Level Security (RLS)

Supabase uses RLS to control data access.

User Profiles

Users can only access their own profile:

alter table user_profiles enable row level security; create policy "Users read own profile" on user_profiles for select using (auth.uid()::text = user_id); create policy "Users insert own profile" on user_profiles for insert with check (auth.uid()::text = user_id); create policy "Users update own profile" on user_profiles for update using (auth.uid()::text = user_id); create policy "Users delete own profile" on user_profiles for delete using (auth.uid()::text = user_id);

Push Tokens

Allow anonymous users to save tokens, with optional user linking:

alter table expo_push_tokens enable row level security; -- Anyone can insert tokens (including anonymous users) create policy "Anyone can insert tokens" on expo_push_tokens for insert with check (true); -- Anyone can update tokens (to link user_id after login) create policy "Anyone can update tokens" on expo_push_tokens for update using (true) with check (true); -- Users can read their own tokens or unassigned tokens create policy "Read own or unassigned tokens" on expo_push_tokens for select using (user_id is null or user_id = auth.uid()::text);