MEga push vol idk, chat function updates, docker fixes
This commit is contained in:
19
supabase/migrations/058_fix_handle_new_org_trigger.sql
Normal file
19
supabase/migrations/058_fix_handle_new_org_trigger.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
-- Fix handle_new_org trigger: use auth.uid() instead of NEW.created_by
|
||||
-- The organizations table has no created_by column, so the trigger was inserting NULL
|
||||
-- as user_id into org_members, causing org creation to fail.
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.handle_new_org()
|
||||
RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = ''
|
||||
AS $$
|
||||
BEGIN
|
||||
-- Add creator as owner (use auth.uid() since organizations has no created_by column)
|
||||
INSERT INTO public.org_members (org_id, user_id, role, joined_at)
|
||||
VALUES (NEW.id, auth.uid(), 'owner', now());
|
||||
-- Create default roles
|
||||
PERFORM public.create_default_org_roles(NEW.id);
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
Reference in New Issue
Block a user