Skip to content

chore(billing): fill subscription_ends_at from Stripe for subscriptions saved before #1358 - #1586

Merged
gkhngyk merged 1 commit into
mainfrom
fix/backfill-subscription-ends-at
Oct 27, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/backfill-subscription-ends-at

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Summary

A one-off script that fills organizations.subscription_ends_at from Stripe for subscriptions saved before #1358, whose period end is empty or already past. #1358 writes it at checkout for new subscriptions only; existing rows wait for their next customer.subscription.updated.

web/scripts/backfill-subscription-ends-at.mjs:

  • Scope: organizations with a stripe_subscription_id, status active, trialing or past_due, and subscription_ends_at null or past. Canceled ones are left alone.
  • What it writes: only subscription_ends_at, read with the same rule as periodEndIso (item-level period end first, then the subscription's own).
  • Status: when Stripe's status differs from the stored one, it's printed, not written. The next webhook event syncs it.
  • Dry run by default. --apply writes. Safe to run again.

Run from web/ with the production keys (STRIPE_SECRET_KEY, NEXT_PUBLIC_SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY):

node --env-file=<env file> scripts/backfill-subscription-ends-at.mjs          # dry run
node --env-file=<env file> scripts/backfill-subscription-ends-at.mjs --apply  # write

Related issue

Follow-up to #1358. No issue.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Chore / maintenance

How to test

  1. Without keys, the script exits with Missing STRIPE_SECRET_KEY.
  2. With production keys, the dry run lists each organization as stored → Stripe and writes nothing.
  3. With --apply, the listed rows get Stripe's period end. A second run finds none of them.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/): eslint clean on the new file
  • yarn typecheck passes (run from web/): plain .mjs, outside the TypeScript build
  • yarn format:check passes (run from web/): prettier clean on the new file
  • Changes are focused — one concern per PR

🤖 Generated with Claude Code

@gkhngyk
gkhngyk merged commit 99a2071 into main Oct 27, 2026
6 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