From 1fac35bf5522be37ce859b47678643be5af34aa6 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sat, 27 Sep 2025 21:13:35 +0000 Subject: [PATCH] Append user_roles table and RLS to migration SQL cgen-abdf4e1ceb8c4048bfea802bc6a41bf3 --- supabase-migration.sql | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/supabase-migration.sql b/supabase-migration.sql index 6fd5f936..e653ebe7 100644 --- a/supabase-migration.sql +++ b/supabase-migration.sql @@ -169,3 +169,20 @@ $$ language 'plpgsql'; CREATE TRIGGER update_user_profiles_updated_at BEFORE UPDATE ON user_profiles FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); CREATE TRIGGER update_projects_updated_at BEFORE UPDATE ON projects FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); CREATE TRIGGER update_community_posts_updated_at BEFORE UPDATE ON community_posts FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); + +-- Create user_roles table for RBAC +CREATE TABLE IF NOT EXISTS user_roles ( + user_id UUID REFERENCES user_profiles(id) ON DELETE CASCADE, + role TEXT NOT NULL, + created_at TIMESTAMPTZ DEFAULT NOW(), + PRIMARY KEY (user_id, role) +); + +-- Enable RLS and add policies for user_roles +ALTER TABLE user_roles ENABLE ROW LEVEL SECURITY; + +-- Users can view and manage their own roles +CREATE POLICY IF NOT EXISTS "Users can view own roles" ON user_roles + FOR SELECT USING (auth.uid() = user_id); +CREATE POLICY IF NOT EXISTS "Users can manage own roles" ON user_roles + FOR ALL USING (auth.uid() = user_id);