Skip to content

Add new migration for signup tracking #3569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 11, 2025
Merged

Add new migration for signup tracking #3569

merged 8 commits into from
Apr 11, 2025

Conversation

colegottdank
Copy link
Collaborator

No description provided.

Copy link

vercel bot commented Apr 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
helicone ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 10, 2025 7:16pm
helicone-bifrost ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 10, 2025 7:16pm
helicone-eu ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 10, 2025 7:16pm

Copy link

fumedev bot commented Apr 8, 2025

Summary

  • Introduces a new SQL migration for tracking user signups in the Supabase database.
  • Creates a system_config table to store tracking settings, with an initial entry to disable tracking by default.
  • Implements a PostgreSQL trigger to call a function that sends user signup data to PostHog if tracking is enabled.
  • Updates user signup flow in the frontend by removing direct PostHog capture calls.
🧪 1 passed
🟢 Test User Signup Error Resilience - Verify Success Despite Tracking Failures
# Database Error Resilience Test for User Signup Tracking

Summary

I verified that user signups complete successfully even when the system_config table is unavailable, testing both email and Google OAuth signup methods.

Implementation

I used a SQL test script executed against the Supabase database container (supabase_db_helicone). The test:

  1. Revoked permissions on system_config to simulate failure:
    REVOKE ALL ON public.system_config FROM postgres;
  2. Inserted test users with required fields:
    -- Email signup
    INSERT INTO auth.users (id, email, encrypted_password, ...) 
    VALUES (gen_random_uuid(), '[email protected]', '$2a$10$abc', ...);
    
    -- OAuth signup  
    INSERT INTO auth.users (id, email, raw_user_meta_data, ...) 
    VALUES (gen_random_uuid(), '[email protected]', '{"provider":"google"}', ...);
  3. Verified user creation via SELECT queries.

Expected Behavior

The trigger function track_user_signup_to_posthog() should gracefully handle failures when querying system_config (via its EXCEPTION blocks), allowing signups to complete regardless of tracking status.

Actual Behavior

Test logs confirmed successful user creation despite revoked permissions:

INSERT 0 1  # Email user
id                  |        email        
--------------------------------------+---------------------
b7b65f1c-69f8-44fc-ac01-b200eb682a12 | [email protected]

INSERT 0 1  # OAuth user  
id                  |           email            |   raw_user_meta_data   
--------------------------------------+----------------------------+------------------------
ff3345bd-4ab9-4a24-ae32-07c105224e80 | [email protected] | {"provider": "google"}

No errors occurred, confirming the trigger’s exception handling worked as designed.

Conclusion

Pass: User signups succeed even when tracking dependencies fail.

'Enable tracking of user signups'
) ON CONFLICT (key) DO NOTHING;
ALTER TABLE public.system_config ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Allow postgres access to system_config" ON public.system_config FOR ALL TO postgres USING (true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fuck RLS

Suggested change
CREATE POLICY "Allow postgres access to system_config" ON public.system_config FOR ALL TO postgres USING (true);

@@ -0,0 +1,69 @@
CREATE EXTENSION IF NOT EXISTS http;
CREATE TABLE IF NOT EXISTS public.system_config (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this table will come in handy a lot, nice

'false',
'Enable tracking of user signups'
) ON CONFLICT (key) DO NOTHING;
ALTER TABLE public.system_config ENABLE ROW LEVEL SECURITY;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ALTER TABLE public.system_config ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.system_config ENABLE ROW LEVEL SECURITY;
REVOKE ALL PRIVILEGES ON TABLE public.system_config FROM anon;
REVOKE ALL PRIVILEGES ON TABLE public.system_config FROM authenticated;

@colegottdank colegottdank merged commit 6185a67 into main Apr 11, 2025
6 of 9 checks passed
@colegottdank colegottdank deleted the fix-posthog-signup branch April 11, 2025 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants