-
-
Notifications
You must be signed in to change notification settings - Fork 67
fix: create stripe_info synchronously on org creation to fix trial delay #1445
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
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughAdds a DB trigger that sets a pending Stripe customer on org creation and backend logic to finalize pending customers. The backend now conditionally calls either customer creation or finalization based on the org's Changes
Sequence DiagramsequenceDiagram
participant Client
participant DB
participant TriggerHandler as on_organization_create
participant SupabaseUtil as finalizePendingStripeCustomer
participant Stripe as Stripe API
Client->>DB: INSERT org row
DB->>DB: Migration trigger sets customer_id = pending_<org_id> and inserts stripe_info
DB->>TriggerHandler: AFTER INSERT event
alt org.customer_id starts with "pending_"
TriggerHandler->>SupabaseUtil: finalizePendingStripeCustomer(org)
SupabaseUtil->>Stripe: create Stripe customer (using org data)
Stripe-->>SupabaseUtil: return real customer_id
SupabaseUtil->>DB: UPDATE orgs set customer_id = real_id
SupabaseUtil->>DB: DELETE stripe_info rows for pending id
else no customer_id
TriggerHandler->>Stripe: create Stripe customer
Stripe-->>TriggerHandler: return customer_id
TriggerHandler->>DB: UPDATE orgs set customer_id = id
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧹 Recent nitpick comments
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used📓 Path-based instructions (9)supabase/functions/_backend/**/*.{ts,js}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
supabase/functions/**/*.{ts,js}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.{vue,ts,tsx,js,jsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
supabase/functions/**/*.ts📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{ts,tsx,js,jsx,vue}📄 CodeRabbit inference engine (AGENTS.md)
Files:
supabase/functions/_backend/**/*.ts📄 CodeRabbit inference engine (AGENTS.md)
Files:
supabase/migrations/**/*.sql📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
supabase/migrations/*.sql📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (13)📚 Learning: 2026-01-10T04:55:25.264ZApplied to files:
📚 Learning: 2025-12-24T14:11:10.256ZApplied to files:
📚 Learning: 2026-01-10T04:55:25.264ZApplied to files:
📚 Learning: 2025-12-25T11:22:13.039ZApplied to files:
📚 Learning: 2026-01-10T04:55:25.264ZApplied to files:
📚 Learning: 2026-01-10T04:55:25.264ZApplied to files:
📚 Learning: 2025-12-23T02:53:12.055ZApplied to files:
📚 Learning: 2026-01-10T04:55:25.264ZApplied to files:
📚 Learning: 2025-12-23T02:53:12.055ZApplied to files:
📚 Learning: 2026-01-10T04:55:25.264ZApplied to files:
📚 Learning: 2025-12-23T02:53:12.055ZApplied to files:
📚 Learning: 2025-12-23T02:53:12.055ZApplied to files:
📚 Learning: 2025-12-23T02:53:12.055ZApplied to files:
🧬 Code graph analysis (1)supabase/functions/_backend/triggers/on_organization_create.ts (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (6)
✏️ Tip: You can disable this entire section by setting Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 SQLFluff (3.5.0)supabase/seed.sqlUser Error: No dialect was specified. You must configure a dialect or specify one on the command line using --dialect after the command. Available dialects: supabase/migrations/20260115051444_sync_stripe_info_on_org_create.sqlUser Error: No dialect was specified. You must configure a dialect or specify one on the command line using --dialect after the command. Available dialects: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
998c0ab to
749f70a
Compare
749f70a to
438f6ec
Compare
|



Summary (AI generated)
stripe_infosynchronously in the database trigger when a new org is createdpending_{org_id}customer_id that is later replaced with the real Stripe customer_idfinalizePendingStripeCustomer()function to safely swap pending → real customer_idgenerate_org_user_on_org_createtogenerate_org_user_stripe_info_on_org_createMotivation (AI generated)
When a user creates a new organization, they immediately see "subscription required" instead of their trial. This happens because:
orgstable (synchronous)on_organization_createjob to pgmq (async)get_orgs_v7()- butstripe_infodoesn't exist yetstripe_infois missing,trial_left = 0and user sees "subscription required"stripe_infowith trialThis fix creates
stripe_infosynchronously with a pending customer_id, so the trial is visible immediately.Business Impact (AI generated)
Test Plan (AI generated)
bun test:backendto ensure no regressionsGenerated with AI
Summary by CodeRabbit
New Features
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.