Files
thrilltrack-explorer/supabase/migrations/20251001131458_b82530cf-f652-48b2-8cd6-391ea391c9b0.sql
2025-10-01 13:16:06 +00:00

26 lines
935 B
PL/PgSQL

-- Drop the problematic functions that try to call edge functions from database
DROP FUNCTION IF EXISTS public.migrate_existing_users_to_novu();
DROP FUNCTION IF EXISTS public.register_novu_subscriber(uuid);
-- Update handle_new_user to only create the profile (remove Novu registration)
CREATE OR REPLACE FUNCTION public.handle_new_user()
RETURNS trigger
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = public
AS $$
BEGIN
-- Create profile record
INSERT INTO public.profiles (user_id, username, display_name)
VALUES (
NEW.id,
COALESCE(NEW.raw_user_meta_data ->> 'username', 'user_' || substring(NEW.id::text, 1, 8)),
COALESCE(NEW.raw_user_meta_data ->> 'display_name', NEW.raw_user_meta_data ->> 'name')
);
-- Novu registration will be handled by the frontend
RETURN NEW;
END;
$$;
COMMENT ON FUNCTION public.handle_new_user IS 'Creates user profile on signup. Novu registration is handled by frontend.';