-- Backfill existing users from auth.users to public.users
INSERT INTO public.users (id, email, full_name, avatar_url, credits)
SELECT 
    id, 
    email, 
    raw_user_meta_data->>'full_name', 
    raw_user_meta_data->>'avatar_url', 
    5 -- Default credits
FROM auth.users
WHERE id NOT IN (SELECT id FROM public.users);
