Skip to content

fix(billing): post-#705 follow-ups — backfill + cleanup#708

Merged
softmarshmallow merged 2 commits into
mainfrom
fix/billing-followup-backfill-and-cleanups
May 7, 2026
Merged

fix(billing): post-#705 follow-ups — backfill + cleanup#708
softmarshmallow merged 2 commits into
mainfrom
fix/billing-followup-backfill-and-cleanups

Conversation

@softmarshmallow

@softmarshmallow softmarshmallow commented May 7, 2026

Copy link
Copy Markdown
Member

Follow-up to #705 (now merged). Two distinct fixes:

1. Production hot-fix: backfill billing rows for pre-migration orgs

#705's 20260506132900_grida_billing.sql adds an AFTER INSERT trigger
that calls fn_provision_account to create the
grida_billing.account and free grida_billing.subscription rows for
new organizations. The trigger only fires on new orgs — pre-existing
ones never got their billing rows.

This blocked first checkout for any pre-migration org with:

Error: resolveOrCreateStripeCustomer attach: billing account not provisioned for organization 255

Single-shot data fix in 20260507000000_grida_billing_backfill_provision.sql:
iterate public.organization and call fn_provision_account for each.
Idempotent — fn_provision_account uses INSERT … ON CONFLICT DO NOTHING.

The guard in fn_attach_stripe_customer stays loud — once the data is
correct, that RAISE is the right behavior for any future anomaly
(deleted row, bypassed trigger, partial restore). Adding self-heal in
the guard's path would silence real signal.

2. UX polish: drop dev test-card hint from upgrade page

Test mode: use card 4242 4242 4242 4242… was an unguarded footer on the
plan cards — visible in production. The test card number belongs in
docs/contributing/billing.md
(where it already lives), not in the customer-facing UI. Other test-mode
copy (the "sandbox" disclaimer at the bottom of /billing) is correctly
gated behind state.is_test_mode — this string was the lone unguarded one.

Test plan

  • Apply migration to production: supabase db push
  • Verify org 255 (and others previously affected) can now reach Stripe Checkout
  • Confirm the test-card hint no longer appears on /organizations/<org>/settings/billing/upgrade
  • Confirm the sandbox disclaimer (gated by is_test_mode) still appears in dev / staging where BILLING_TEST_MODE=true

Related

Summary by CodeRabbit

  • Bug Fixes

    • Removed test mode information from the billing upgrade view.
  • Chores

    • Added database migration to backfill billing provisioning for existing organizations.

Production blocker: orgs created BEFORE 20260506132900 never got their
`grida_billing.account` and free `grida_billing.subscription` rows. The
provisioning trigger only fires on `AFTER INSERT`, so existing orgs were
left empty. First checkout for those orgs crashed with:

    Error: resolveOrCreateStripeCustomer attach: billing account not
    provisioned for organization 255

Single-shot data fix: iterate `public.organization` and call
`fn_provision_account` for each (idempotent — INSERT … ON CONFLICT DO
NOTHING). The guard in `fn_attach_stripe_customer` stays loud — once
the data is correct, that RAISE is the right behavior for any future
anomaly (deleted row, bypassed trigger, partial restore). Self-heal in
the guard's path would silence real signal.
The string "Test mode: use card 4242 4242 4242 4242…" was an unguarded
footer on the plan cards — visible in production. The test card number
belongs in docs/contributing/billing.md (where it already lives), not in
the customer-facing UI.

Other test-mode UI is properly gated behind state.is_test_mode (the
sandbox disclaimer at the bottom of /billing); this string was the lone
unguarded one.
@vercel

vercel Bot commented May 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blog Ready Ready Preview, Comment May 7, 2026 1:05pm
docs Ready Ready Preview, Comment May 7, 2026 1:05pm
grida Ready Ready Preview, Comment May 7, 2026 1:05pm
viewer Ready Ready Preview, Comment May 7, 2026 1:05pm
3 Skipped Deployments
Project Deployment Actions Updated (UTC)
backgrounds Ignored Ignored Preview May 7, 2026 1:05pm
code Ignored Ignored May 7, 2026 1:05pm
legacy Ignored Ignored May 7, 2026 1:05pm

Request Review

@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 207a860d-0cab-427a-9bc1-a5ad1a5f92b1

📥 Commits

Reviewing files that changed from the base of the PR and between 6e6617e and 7852e25.

📒 Files selected for processing (2)
  • editor/app/(site)/organizations/[organization_name]/settings/billing/upgrade/_view.tsx
  • supabase/migrations/20260507000000_grida_billing_backfill_provision.sql

Walkthrough

Adds a one-time DB migration that provisions billing for all existing organizations and removes the "Test mode" informational paragraph from the billing upgrade UI.

Changes

Billing Account Provisioning

Layer / File(s) Summary
Database Backfill Migration
supabase/migrations/20260507000000_grida_billing_backfill_provision.sql
Anonymous PL/pgSQL block iterates all rows in public.organization, calls grida_billing.fn_provision_account() per org_id, increments a counter, and emits a NOTICE with the processed count.
UI Test Mode Notice Removal
editor/app/(site)/organizations/[organization_name]/settings/billing/upgrade/_view.tsx
Removes the "Test mode" paragraph that described the Stripe test card and post-payment provisioning redirect behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • gridaco/grida#708: The main PR makes the same two code-level changes as the retrieved PR—removing the test-card info from the billing upgrade view and adding the idempotent backfill migration to provision billing for existing organizations—so they are related.
  • gridaco/grida#705: Main PR directly modifies the same UpgradeView component (editor/.../upgrade/_view.tsx) from PR #705 by removing the “Test mode” informational paragraph, so the changes are related.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/billing-followup-backfill-and-cleanups

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.

🔧 Microsoft Presidio Analyzer (2.2.362)
supabase/migrations/20260507000000_grida_billing_backfill_provision.sql

Microsoft Presidio Analyzer failed to scan this file


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@softmarshmallow softmarshmallow merged commit 41ce72d into main May 7, 2026
14 of 15 checks passed
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.

1 participant