organization_billing API Postgres table
Per-organization sync billing state.
Declared in packages/api-shared/src/schema/organizations.ts
Description
Sync is the single paid feature: an organization's containers, documents, and blobs sync to the server only while its billing can sync. The product is free to use fully locally, so every organization owns exactly one billing row and it starts local (on-device only, no server sync). Enabling sync starts a trial, and a paid subscription keeps it active. This is uniform for every organization — the personal organization created at registration is just an organization that has not started a subscription.
Access authority is unchanged: signed groups and container grants still decide who can touch what. This row only decides whether the owning organization may sync at all.
Columns
iduuid- primary key
- not null
- default gen_random_uuid()
Billing row id. Lookups go through the unique
organizationId.organization_iduuid- not null
Organization this billing row belongs to (one per org).
statustext- not null
- default 'local'
Sync-billing lifecycle.
local(free, on-device only),trialingandactivecan sync;disabled,deleting,purgedcannot.trial_ends_attimestamp- nullable
When the free trial ends. Null unless
statusistrialing.trial_expiry_next_attempt_attimestamp- nullable
Durable retry state for the out-of-process trial-expiry sweep. A failed row backs off so it cannot starve later due trials.
trial_expiry_attempt_countinteger- not null
- default 0
Durable retry state for the out-of-process trial-expiry sweep. A failed row backs off so it cannot starve later due trials.
trial_expiry_last_errortext- nullable
Durable retry state for the out-of-process trial-expiry sweep. A failed row backs off so it cannot starve later due trials.
providertext- nullable
Payment provider backing an
activesubscription (RevenueCat). Null whilelocal/trialing.provider_customer_idtext- nullable
Provider-side customer id (RevenueCat App User ID) that purchased the subscription.
provider_subscription_idtext- nullable
Provider-side stable subscription/original transaction id, when the provider reports one.
provider_product_idtext- nullable
Latest provider product and transaction ids applied to this billing row.
provider_transaction_idtext- nullable
Latest provider product and transaction ids applied to this billing row.
entitlement_idtext- nullable
Provider entitlement granting sync for this organization.
current_period_starts_attimestamp- nullable
Start of the paid period reported by the provider.
current_period_ends_attimestamp- nullable
End of the paid period reported by the provider; sync lapses if it passes without renewal.
seat_countinteger- not null
- default 0
Licensed seats for the current paid billing period. Seat switches are reconciled by
organization_billing_seat_assignments.seat_period_keytext- nullable
Explicit identity of the trial/paid period represented by
seatCount. This cannot be inferred from open assignments because an organization can legitimately have none at period rollover.checkout_attempt_idtext- nullable
Durable, organization-scoped ownership of an unpaid Stripe checkout. Inline and hosted checkout share this guard so they cannot race into two subscriptions. The captured seat quantity remains fixed for an idempotent retry and the token rotates after expiry.
checkout_attempt_modetext- nullable
Durable, organization-scoped ownership of an unpaid Stripe checkout. Inline and hosted checkout share this guard so they cannot race into two subscriptions. The captured seat quantity remains fixed for an idempotent retry and the token rotates after expiry.
checkout_attempt_user_iduuid- nullable
Durable, organization-scoped ownership of an unpaid Stripe checkout. Inline and hosted checkout share this guard so they cannot race into two subscriptions. The captured seat quantity remains fixed for an idempotent retry and the token rotates after expiry.
checkout_attempt_seat_quantityinteger- nullable
Durable, organization-scoped ownership of an unpaid Stripe checkout. Inline and hosted checkout share this guard so they cannot race into two subscriptions. The captured seat quantity remains fixed for an idempotent retry and the token rotates after expiry.
checkout_attempt_started_attimestamp- nullable
Durable, organization-scoped ownership of an unpaid Stripe checkout. Inline and hosted checkout share this guard so they cannot race into two subscriptions. The captured seat quantity remains fixed for an idempotent retry and the token rotates after expiry.
checkout_attempt_expires_attimestamp- nullable
Durable, organization-scoped ownership of an unpaid Stripe checkout. Inline and hosted checkout share this guard so they cannot race into two subscriptions. The captured seat quantity remains fixed for an idempotent retry and the token rotates after expiry.
disabled_attimestamp- nullable
Set when sync lapses. The purge job may delete the organization's remote sync data after
purgeAfter.purge_aftertimestamp- nullable
Set when sync lapses. The purge job may delete the organization's remote sync data after
purgeAfter.purge_started_attimestamp- nullable
Purge job progress and fencing markers.
purge_lease_iduuid- nullable
Purge job progress and fencing markers.
purged_attimestamp- nullable
Purge job progress and fencing markers.
replacement_organization_iduuid- nullable
Durable old-to-new personal-organization handoff. These make a lost provisioning response retryable after the user's default pointer has moved.
replacement_provisioning_responsejsonb- nullable
Durable old-to-new personal-organization handoff. These make a lost provisioning response retryable after the user's default pointer has moved.
native_restore_user_iduuid- nullable
Durable native-subscription restore intent. The server stores a request commitment and provisioning response for idempotent client replay, and records when the fresh destination has been claimed.
native_restore_claimed_attimestamp- nullable
Durable native-subscription restore intent. The server stores a request commitment and provisioning response for idempotent client replay, and records when the fresh destination has been claimed.
native_restore_provisioning_responsejsonb- nullable
Durable native-subscription restore intent. The server stores a request commitment and provisioning response for idempotent client replay, and records when the fresh destination has been claimed.
native_restore_provisioning_request_sha256text- nullable
Durable native-subscription restore intent. The server stores a request commitment and provisioning response for idempotent client replay, and records when the fresh destination has been claimed.
created_attimestamp- not null
- default now()
Server-side row timestamps.
updated_attimestamp- not null
- default now()
Server-side row timestamps.
Indexes
organization_billing_org_idx(organization_id)- unique
organization_billing_trial_expiry_idx(status, trial_ends_at, trial_expiry_next_attempt_at, organization_id)organization_billing_purge_candidates_idx(status, purge_after, purge_started_at, organization_id)organization_billing_provider_subscription_idx(provider_subscription_id)- unique
Greenfield invariant: one store subscription funds one organization. Prelaunch databases with conflicting fixtures are reset, not backfilled.
organization_billing_provider_customer_idx(provider, provider_customer_id)