Billing
Organization credits, ledger entries, and email send tracking.
Source: packages/db/src/schema/billing.ts
Enums
| Enum | Values |
|---|---|
billing_cycle | monthly, annual |
subscription_status | active, past_due, cancelled, trialing, paused |
ledger_entry_type | credit_purchased, email_sent, rollover_applied, manual_adjustment, refund, plan_change, period_reset |
email_send_status | queued, sent, skipped, failed, bounced |
skip_reason | over_limit, unsubscribed, duplicate, invalid_address, suppressed, dry_run |
invoice_status | draft, open, paid, void, uncollectible |
organization_credits
| Column | Type | Notes |
|---|---|---|
id | text | PK, prefix ocr_ |
organization_id | text | FK → organization.id, CASCADE, UNIQUE |
credits_used | integer | default 0 |
credits_remaining | integer | default 3000 |
monthly_credits | integer | default 3000 |
current_period_start | timestamp | |
current_period_end | timestamp | NOT NULL |
status | varchar(50) | default active |
created_at | timestamp | |
updated_at | timestamp |
credit_ledger
| Column | Type | Notes |
|---|---|---|
id | text | PK, prefix cld_ |
organization_id | text | FK → organization.id, CASCADE |
organization_credits_id | text | FK → organization_credits.id, CASCADE |
entry_type | ledger_entry_type | NOT NULL |
delta | integer | NOT NULL |
balance_after | integer | NOT NULL |
reason | text | |
reference_id | text | points to email_send.id |
created_at | timestamp |
email_send
| Column | Type | Notes |
|---|---|---|
id | text | PK, prefix esn_ |
organization_id | text | FK → organization.id, CASCADE |
organization_credits_id | text | FK → organization_credits.id, CASCADE |
email_log_id | text | FK → email_log.id |
recipient_email | varchar(255) | NOT NULL |
counted_in_credits | boolean | default true |
credits_consumed | integer | default 1 |
status | email_send_status | default queued |
error_message | text | |
sent_at | timestamp | |
created_at | timestamp |
Was this page helpful?