Skip to content

fix(db): exempt credit-only orgs from canceled retention - #2979

Merged
riderx merged 1 commit into
mainfrom
fix/exempt-credit-orgs-canceled-retention
Aug 10, 2026
Merged

fix(db): exempt credit-only orgs from canceled retention#2979
riderx merged 1 commit into
mainfrom
fix/exempt-credit-orgs-canceled-retention

Conversation

@riderx

@riderx riderx commented Aug 10, 2026

Copy link
Copy Markdown
Member

Summary (AI generated)

  • Exclude orgs with has_usage_credits from canceled_org_ids_past_grace and retention warning queue
  • Prevents credit-only orgs (canceled Stripe trial, paying via credits) from bundle soft-delete / 95-day app archive
  • Extends pgTAP coverage for a long-canceled credit-funded org

Fixes #2974

Motivation (AI generated)

#2929 retention only checked stripe_info.status IN ('canceled','deleted'). Credit-only orgs stay canceled after trial while actively paying with usage credits, so the sweep deleted their production bundles. #2789 already introduced has_usage_credits_org for the CLI; retention never consulted the same flag.

Business Impact (AI generated)

Stops deleting paying credit customers' apps/bundles. Protects credit billing path from false unpaid retention.

Test Plan (AI generated)

  • bun scripts/supabase-worktree.ts test db (includes 64_test_canceled_org_version_cleanup.sql)
  • Confirm credit-only org is absent from canceled_org_ids_past_grace(90) / (95) in prod after migrate
  • Separately restore soft-deleted bundles for affected org f81009da-e037-4ad9-bfee-f6d2674d9bb9

Generated with AI

Made with Cursor


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Review in cubic

Summary by CodeRabbit

  • New Features

    • Added retention safeguards for canceled organizations with active usage credits.
    • Added automated eligibility checks and batching for retention alerts.
    • Retention alerts now include deletion timing and relevant app details.
  • Bug Fixes

    • Prevented credit-funded organizations, apps, and versions from being removed during cleanup.
    • Prevented retention warnings from being sent to organizations protected by active usage credits.

Canceled orgs with active usage credits were swept as unpaid after trial end.
Exclude has_usage_credits from grace eligibility and retention warnings.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6094186c-fbed-419f-b63c-39980afc679c

📥 Commits

Reviewing files that changed from the base of the PR and between a071b1d and 0cc58b6.

📒 Files selected for processing (2)
  • supabase/migrations/20260810095528_exempt_credit_orgs_from_canceled_retention.sql
  • supabase/tests/64_test_canceled_org_version_cleanup.sql

📝 Walkthrough

Walkthrough

The migration adds retention helpers that exclude organizations with active usage credits from cleanup and warning alerts. The test suite adds a credit-funded canceled organization and verifies that its apps, versions, and retention state remain intact.

Changes

Canceled retention exemption

Layer / File(s) Summary
Grace-period selection and access control
supabase/migrations/20260810095528_exempt_credit_orgs_from_canceled_retention.sql
Adds canceled_org_ids_past_grace, which excludes organizations with usage credits and allows service-role access only.
Retention alert batching and queueing
supabase/migrations/20260810095528_exempt_credit_orgs_from_canceled_retention.sql
Validates alert types, selects eligible organizations within the retention window, removes duplicates, and queues alerts through pgmq.
Usage-credit retention test coverage
supabase/tests/64_test_canceled_org_version_cleanup.sql
Adds fixtures and assertions confirming that usage-credit organizations retain apps and versions and receive no deletion warnings.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RetentionSweep
  participant SupabaseFunctions
  participant pgmq
  RetentionSweep->>SupabaseFunctions: request canceled-org retention alerts
  SupabaseFunctions->>SupabaseFunctions: exclude usage-credit organizations
  SupabaseFunctions->>pgmq: enqueue eligible retention alerts
  pgmq-->>RetentionSweep: return queued count
Loading

Possibly related PRs

Suggested labels: codex

Suggested reviewers: dalanir


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

@riderx
riderx merged commit a324b25 into main Aug 10, 2026
58 of 60 checks passed
@riderx
riderx deleted the fix/exempt-credit-orgs-canceled-retention branch August 10, 2026 10:01
@coderabbitai coderabbitai Bot added the codex label Aug 10, 2026
@codspeed-hq

codspeed-hq Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing fix/exempt-credit-orgs-canceled-retention (0cc58b6) with main (a071b1d)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@sonarqubecloud

Copy link
Copy Markdown

@cursor
cursor Bot requested review from Dalanir and WcaleNieWolny August 10, 2026 10:04

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Risk: high. Left a non-blocking comment — Bugbot passed with no findings, but this migration changes billing/retention eligibility for credit-funded orgs, which is above the low approval threshold. Human review needed; assigning reviewers.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver External

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New canceled-org retention sweep deletes bundles of credit-only orgs (never checks has_usage_credits_org)

1 participant