Skip to Content
ArchitectureDatabase Schema

Database Schema

RustBill uses PostgreSQL 17 with migrations managed by SQLx. All tables use UUID primary keys and timestamptz for timestamps.

Entity Relationship Diagram

Core Tables

products

The product catalog. Supports three product types with type-specific nullable fields.

ColumnTypeDescription
idUUIDPrimary key
nameVARCHAR(255)Product name
product_typeproduct_typelicensed, saas, or api
descriptionTEXTOptional description
priceDECIMAL(12,2)Base price
statusVARCHAR(50)active, inactive, etc.
monthly_revenueDECIMAL(12,2)Revenue tracking metric
active_usersINTEGERMAU metric
daily_active_usersINTEGERDAU metric
churn_rateDECIMAL(5,2)Churn percentage

customers

ColumnTypeDescription
idUUIDPrimary key
nameVARCHAR(255)Customer name
emailVARCHAR(255)Unique email
companyVARCHAR(255)Company name
tiercustomer_tierstarter, professional, enterprise
billing_addressTEXTBilling address
tax_idVARCHAR(100)Tax identifier
payment_methodpayment_methodDefault payment method
health_scoreINTEGERCustomer health (0-100)
credit_balanceDECIMAL(12,2)Store credit balance

subscriptions

ColumnTypeDescription
idUUIDPrimary key
customer_idUUIDFK to customers
plan_idUUIDFK to plans
statussubscription_statusactive, paused, canceled, past_due, trialing
billing_cyclebilling_cyclemonthly, quarterly, yearly
current_period_startTIMESTAMPTZStart of current billing period
current_period_endTIMESTAMPTZEnd of current billing period
cancel_at_period_endBOOLEANWhether to cancel at period end
trial_endTIMESTAMPTZTrial period end date

invoices

ColumnTypeDescription
idUUIDPrimary key
customer_idUUIDFK to customers
subscription_idUUIDFK to subscriptions (nullable)
invoice_numberVARCHAR(50)Unique human-readable number
statusinvoice_statusdraft, issued, paid, overdue, void
subtotalDECIMAL(12,2)Before tax
tax_amountDECIMAL(12,2)Tax total
totalDECIMAL(12,2)Final amount
currencyVARCHAR(3)ISO currency code
due_dateTIMESTAMPTZPayment due date
paid_atTIMESTAMPTZWhen payment was received
line_itemsJSONBArray of line item objects
pdf_urlTEXTGenerated PDF location

licenses

ColumnTypeDescription
idUUIDPrimary key
license_keyVARCHAR(255)Unique license key string
customer_idUUIDFK to customers
product_idUUIDFK to products
statusVARCHAR(50)active, expired, revoked, suspended
max_activationsINTEGERDevice activation limit
current_activationsINTEGERCurrent active devices
featuresJSONBLicensed features map
expires_atTIMESTAMPTZExpiration date

Enums

See the Database Enums reference for all PostgreSQL enum types and their values.

Migrations

Migrations live in the migrations/ directory and are run automatically on server startup. They can also be run manually:

cargo sqlx migrate run

To create a new migration:

cargo sqlx migrate add <description>
Last updated on