This directory contains the database schema and setup scripts for Careloop.
supabase-setup.sql- Complete Supabase database schema with tables, RLS policies, functions, and triggers
- Go to supabase.com
- Create a new project
- Wait for the project to be ready
- Open your Supabase project dashboard
- Navigate to SQL Editor
- Copy the contents of
supabase-setup.sql - Paste and run the SQL
This will create:
- User groups for task collaboration
- Fields:
id,name,admin_id,created_at,updated_at
- User profiles linked to auth.users
- Fields:
id,group_id,display_name,created_at,updated_at
- Task items with group association
- Fields:
id,user_id,group_id,label,is_completed,date_and_time,reward,notes,icon,author_name
- Comments on tasks
- Fields:
id,created_at,comment_content,todo_id,user_id,author_name
All tables have RLS enabled with policies that ensure:
- Users can only access data from their groups
- Admins can manage their groups
- Users can manage their own profiles
- Proper data isolation between groups
Returns all members of a specific group.
Trigger function that automatically creates user profiles when users sign up.
Performance indexes on commonly queried fields:
profiles.group_idtodos.group_id,todos.user_id,todos.date_and_timecomments.todo_id,comments.created_at
Enabled for todos and comments tables to support live collaboration features.
"Table doesn't exist" errors:
- Ensure you ran the complete SQL script
- Check that all tables were created successfully
Permission denied errors:
- RLS policies might be blocking access
- Verify user authentication is working
- Check that user profiles exist
Missing user profile:
- The trigger should create profiles automatically for new users
- For existing users, manually insert into profiles table:
INSERT INTO profiles (id, display_name)
VALUES ('USER_ID_HERE', 'Display Name')
ON CONFLICT (id) DO NOTHING;To verify the setup worked:
-- Check tables exist
SELECT table_name FROM information_schema.tables
WHERE table_schema = 'public';
-- Check RLS is enabled
SELECT tablename, rowsecurity
FROM pg_tables
WHERE schemaname = 'public';
-- Check policies exist
SELECT schemaname, tablename, policyname, permissive, roles, cmd, qual
FROM pg_policies
WHERE schemaname = 'public';When modifying the database schema:
- Update
supabase-setup.sqlwith your changes - Test changes on a development database first
- Document any breaking changes
- Consider migration scripts for production updates