This repo contains:
supabase/schema.sql: Postgres schema forprofiles,events,tasks,event_study_days+ enums + RLS.supabase/migrations/0001_init.sql: migration copy ofschema.sql(usable with Supabase CLI).lib/: Supabase browser/server clients, typed helpers, and TanStack Query hooks for CRUD + timeline queries.supabase/tests/rls_compile.sql+scripts/verify-rls.mjs: lightweight checks to ensure policies exist and compile.
Create a .env (see .env.example).
Required for browser usage:
NEXT_PUBLIC_SUPABASE_URLNEXT_PUBLIC_SUPABASE_ANON_KEY
Optional for server usage:
SUPABASE_URL(fallback whenNEXT_PUBLIC_SUPABASE_URLis not set)SUPABASE_ANON_KEY(fallback whenNEXT_PUBLIC_SUPABASE_ANON_KEYis not set)SUPABASE_SERVICE_ROLE_KEY(for server-to-server/admin operations)
Optional for the DB verification script:
DATABASE_URL(e.g. Supabase local:postgresql://postgres:postgres@localhost:54322/postgres)
- Install the Supabase CLI: https://supabase.com/docs/guides/cli
- Start local stack:
supabase start- Apply migrations:
supabase db resetIf you want to apply the schema directly without migrations:
psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f supabase/schema.sqlYou can also run the policy assertions:
psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f supabase/schema.sql -f supabase/tests/rls_compile.sqlnpm testnpm run verify:rlsThis runs supabase/schema.sql inside a transaction and verifies that the expected RLS policies exist.
- All user-owned tables include a
user_idcolumn and have RLS policies enforcinguser_id = auth.uid(). - Study-task linkage:
tasks.is_study_taskflags a task as a study task.tasks.event_study_day_idmust be non-null whenis_study_task = true, and must be null whenis_study_task = false(enforced by a CHECK constraint).
import {
getSupabaseBrowserClient,
useEvents,
useEventTimeline,
useCreateTask,
} from './lib/index.js';
const supabase = getSupabaseBrowserClient();
// In React
// const { data: events } = useEvents(supabase)
// const { data: timeline } = useEventTimeline(eventId, supabase)
// const createTask = useCreateTask(eventId, supabase)