Skip to content

Schema: billing

Part of the generated database reference.

billing_alert_history

  • Domain: billing Β· Feature gate: #[cfg(feature = "billing")] Β· Migration: 6.5.23-branch-scope-cleanup
  • Rust source: botschema/src/billing/alerts.rs
Column SQL type Null Default Key References
id UUID no gen_random_uuid() PK β€”
org_id UUID no β€” FK organizations.org_id
bot_id UUID no β€” β€” β€”
alert_id UUID no β€” β€” β€”
metric VARCHAR(255) no β€” β€” β€”
severity VARCHAR(255) no β€” β€” β€”
current_usage BIGINT no β€” β€” β€”
usage_limit BIGINT no β€” β€” β€”
percentage NUMERIC no β€” β€” β€”
message TEXT no β€” β€” β€”
acknowledged_at TIMESTAMPTZ yes β€” β€” β€”
acknowledged_by UUID yes β€” β€” β€”
resolved_at TIMESTAMPTZ yes β€” β€” β€”
resolution_type VARCHAR(255) yes β€” β€” β€”
created_at TIMESTAMPTZ no NOW() β€” β€”
branch_id UUID yes β€” FK branches.id

billing_grace_periods

  • Domain: billing Β· Feature gate: #[cfg(feature = "billing")] Β· Migration: 6.5.23-branch-scope-cleanup
  • Rust source: botschema/src/billing/alerts.rs
Column SQL type Null Default Key References
id UUID no gen_random_uuid() PK β€”
org_id UUID no β€” FK organizations.org_id
bot_id UUID no β€” β€” β€”
metric VARCHAR(255) no β€” β€” β€”
started_at TIMESTAMPTZ no NOW() β€” β€”
expires_at TIMESTAMPTZ no β€” β€” β€”
overage_at_start NUMERIC no β€” β€” β€”
current_overage NUMERIC no β€” β€” β€”
max_allowed_overage NUMERIC no β€” β€” β€”
is_active BOOLEAN no TRUE β€” β€”
ended_at TIMESTAMPTZ yes β€” β€” β€”
end_reason VARCHAR(255) yes β€” β€” β€”
created_at TIMESTAMPTZ no NOW() β€” β€”
updated_at TIMESTAMPTZ no NOW() β€” β€”
branch_id UUID yes β€” FK branches.id

billing_invoice_items

  • Domain: billing Β· Feature gate: #[cfg(feature = "billing")] Β· Migration: 6.5.15.1-consolidated
  • Rust source: botschema/src/billing/invoices.rs
Column SQL type Null Default Key References
id UUID no gen_random_uuid() PK β€”
invoice_id UUID no β€” FK billing_invoices.id
product_id UUID yes β€” β€” β€”
description VARCHAR(255) no β€” β€” β€”
quantity NUMERIC no 1 β€” β€”
unit_price NUMERIC no β€” β€” β€”
discount_percent NUMERIC no 0 β€” β€”
tax_rate NUMERIC no 0 β€” β€”
amount NUMERIC no β€” β€” β€”
sort_order INTEGER no 0 β€” β€”
created_at TIMESTAMPTZ no NOW() β€” β€”

billing_invoices

  • Domain: billing Β· Feature gate: #[cfg(feature = "billing")] Β· Migration: 6.5.23-branch-scope-cleanup
  • Rust source: botschema/src/billing/invoices.rs
Column SQL type Null Default Key References
id UUID no gen_random_uuid() PK β€”
org_id UUID no β€” FK branches.id
bot_id UUID no β€” β€” β€”
invoice_number VARCHAR(255) no β€” β€” β€”
customer_id UUID yes β€” β€” β€”
customer_name VARCHAR(255) no β€” β€” β€”
customer_email VARCHAR(255) yes β€” β€” β€”
customer_address TEXT yes β€” β€” β€”
status VARCHAR(255) no 'draft' β€” β€”
issue_date VARCHAR(255) no β€” β€” β€”
due_date VARCHAR(255) no β€” β€” β€”
subtotal NUMERIC no 0 β€” β€”
tax_rate NUMERIC no 0 β€” β€”
tax_amount NUMERIC no 0 β€” β€”
discount_percent NUMERIC no 0 β€” β€”
discount_amount NUMERIC no 0 β€” β€”
total NUMERIC no 0 β€” β€”
amount_paid NUMERIC no 0 β€” β€”
amount_due NUMERIC no 0 β€” β€”
currency VARCHAR(255) no 'USD' β€” β€”
notes TEXT yes β€” β€” β€”
terms TEXT yes β€” β€” β€”
footer TEXT yes β€” β€” β€”
paid_at TIMESTAMPTZ yes β€” β€” β€”
sent_at TIMESTAMPTZ yes β€” β€” β€”
voided_at TIMESTAMPTZ yes β€” β€” β€”
created_at TIMESTAMPTZ no NOW() β€” β€”
updated_at TIMESTAMPTZ no NOW() β€” β€”
branch_id UUID yes β€” FK branches.id

billing_notification_preferences

  • Domain: billing Β· Feature gate: #[cfg(feature = "billing")] Β· Migration: 6.5.23-branch-scope-cleanup
  • Rust source: botschema/src/billing/alerts.rs
Column SQL type Null Default Key References
id UUID no gen_random_uuid() PK β€”
org_id UUID no β€” UQ, FK organizations.org_id
bot_id UUID no β€” β€” β€”
enabled BOOLEAN no TRUE β€” β€”
channels JSONB no '["email", "in_app"]'::jsonb β€” β€”
email_recipients JSONB no '[]'::jsonb β€” β€”
webhook_url TEXT yes β€” β€” β€”
webhook_secret TEXT yes β€” β€” β€”
slack_webhook_url TEXT yes β€” β€” β€”
teams_webhook_url TEXT yes β€” β€” β€”
sms_numbers JSONB no '[]'::jsonb β€” β€”
min_severity VARCHAR(255) no 'warning' β€” β€”
quiet_hours_start INTEGER yes β€” β€” β€”
quiet_hours_end INTEGER yes β€” β€” β€”
quiet_hours_timezone VARCHAR(255) yes β€” β€” β€”
quiet_hours_days JSONB yes '[]'::jsonb β€” β€”
metric_overrides JSONB no '{}'::jsonb β€” β€”
created_at TIMESTAMPTZ no NOW() β€” β€”
updated_at TIMESTAMPTZ no NOW() β€” β€”
branch_id UUID yes β€” FK branches.id

billing_payments

  • Domain: billing Β· Feature gate: #[cfg(feature = "billing")] Β· Migration: 6.5.23-branch-scope-cleanup
  • Rust source: botschema/src/billing/payments.rs
Column SQL type Null Default Key References
id UUID no gen_random_uuid() PK β€”
org_id UUID no β€” FK branches.id
bot_id UUID no β€” β€” β€”
invoice_id UUID yes β€” FK billing_invoices.id
payment_number VARCHAR(255) no β€” β€” β€”
amount NUMERIC no β€” β€” β€”
currency VARCHAR(255) no 'USD' β€” β€”
payment_method VARCHAR(255) no 'other' β€” β€”
payment_reference VARCHAR(255) yes β€” β€” β€”
status VARCHAR(255) no 'completed' β€” β€”
payer_name VARCHAR(255) yes β€” β€” β€”
payer_email VARCHAR(255) yes β€” β€” β€”
notes TEXT yes β€” β€” β€”
paid_at TIMESTAMPTZ no NOW() β€” β€”
refunded_at TIMESTAMPTZ yes β€” β€” β€”
refund_amount NUMERIC yes β€” β€” β€”
created_at TIMESTAMPTZ no NOW() β€” β€”
branch_id UUID yes β€” FK branches.id

billing_quote_items

  • Domain: billing Β· Feature gate: #[cfg(feature = "billing")] Β· Migration: 6.5.15.1-consolidated
  • Rust source: botschema/src/billing/payments.rs
Column SQL type Null Default Key References
id UUID no gen_random_uuid() PK β€”
quote_id UUID no β€” FK billing_quotes.id
product_id UUID yes β€” β€” β€”
description VARCHAR(255) no β€” β€” β€”
quantity NUMERIC no 1 β€” β€”
unit_price NUMERIC no β€” β€” β€”
discount_percent NUMERIC no 0 β€” β€”
tax_rate NUMERIC no 0 β€” β€”
amount NUMERIC no β€” β€” β€”
sort_order INTEGER no 0 β€” β€”
created_at TIMESTAMPTZ no NOW() β€” β€”

billing_quotes

  • Domain: billing Β· Feature gate: #[cfg(feature = "billing")] Β· Migration: 6.5.23-branch-scope-cleanup
  • Rust source: botschema/src/billing/payments.rs
Column SQL type Null Default Key References
id UUID no gen_random_uuid() PK β€”
org_id UUID no β€” FK branches.id
bot_id UUID no β€” β€” β€”
quote_number VARCHAR(255) no β€” β€” β€”
customer_id UUID yes β€” β€” β€”
customer_name VARCHAR(255) no β€” β€” β€”
customer_email VARCHAR(255) yes β€” β€” β€”
customer_address TEXT yes β€” β€” β€”
status VARCHAR(255) no 'draft' β€” β€”
issue_date VARCHAR(255) no β€” β€” β€”
valid_until VARCHAR(255) no β€” β€” β€”
subtotal NUMERIC no 0 β€” β€”
tax_rate NUMERIC no 0 β€” β€”
tax_amount NUMERIC no 0 β€” β€”
discount_percent NUMERIC no 0 β€” β€”
discount_amount NUMERIC no 0 β€” β€”
total NUMERIC no 0 β€” β€”
currency VARCHAR(255) no 'USD' β€” β€”
notes TEXT yes β€” β€” β€”
terms TEXT yes β€” β€” β€”
accepted_at TIMESTAMPTZ yes β€” β€” β€”
rejected_at TIMESTAMPTZ yes β€” β€” β€”
converted_invoice_id UUID yes β€” FK billing_invoices.id
sent_at TIMESTAMPTZ yes β€” β€” β€”
created_at TIMESTAMPTZ no NOW() β€” β€”
updated_at TIMESTAMPTZ no NOW() β€” β€”
branch_id UUID yes β€” FK branches.id

billing_recurring

  • Domain: billing Β· Feature gate: #[cfg(feature = "billing")] Β· Migration: 6.5.23-branch-scope-cleanup
  • Rust source: botschema/src/billing/payments.rs
Column SQL type Null Default Key References
id UUID no gen_random_uuid() PK β€”
org_id UUID no β€” FK branches.id
bot_id UUID no β€” β€” β€”
customer_id UUID yes β€” β€” β€”
customer_name VARCHAR(255) no β€” β€” β€”
customer_email VARCHAR(255) yes β€” β€” β€”
status VARCHAR(255) no 'active' β€” β€”
frequency VARCHAR(255) no 'monthly' β€” β€”
interval_count INTEGER no 1 β€” β€”
amount NUMERIC no β€” β€” β€”
currency VARCHAR(255) no 'USD' β€” β€”
description TEXT yes β€” β€” β€”
next_invoice_date VARCHAR(255) no β€” β€” β€”
last_invoice_date VARCHAR(255) yes β€” β€” β€”
last_invoice_id UUID yes β€” FK billing_invoices.id
start_date VARCHAR(255) no β€” β€” β€”
end_date VARCHAR(255) yes β€” β€” β€”
invoices_generated INTEGER no 0 β€” β€”
created_at TIMESTAMPTZ no NOW() β€” β€”
updated_at TIMESTAMPTZ no NOW() β€” β€”
branch_id UUID yes β€” FK branches.id

billing_tax_rates

  • Domain: billing Β· Feature gate: #[cfg(feature = "billing")] Β· Migration: 6.5.23-branch-scope-cleanup
  • Rust source: botschema/src/billing/payments.rs
Column SQL type Null Default Key References
id UUID no gen_random_uuid() PK β€”
org_id UUID no β€” FK organizations.org_id
bot_id UUID no β€” β€” β€”
name VARCHAR(255) no β€” β€” β€”
rate NUMERIC no β€” β€” β€”
description TEXT yes β€” β€” β€”
region VARCHAR(255) yes β€” β€” β€”
is_default BOOLEAN no FALSE β€” β€”
is_active BOOLEAN no TRUE β€” β€”
created_at TIMESTAMPTZ no NOW() β€” β€”
branch_id UUID yes β€” FK branches.id

billing_usage_alerts

  • Domain: billing Β· Feature gate: #[cfg(feature = "billing")] Β· Migration: 6.5.23-branch-scope-cleanup
  • Rust source: botschema/src/billing/alerts.rs
Column SQL type Null Default Key References
id UUID no gen_random_uuid() PK β€”
org_id UUID no β€” FK organizations.org_id
bot_id UUID no β€” β€” β€”
metric VARCHAR(255) no β€” β€” β€”
severity VARCHAR(255) no β€” β€” β€”
current_usage BIGINT no β€” β€” β€”
usage_limit BIGINT no β€” β€” β€”
percentage NUMERIC no β€” β€” β€”
threshold NUMERIC no β€” β€” β€”
message TEXT no β€” β€” β€”
acknowledged_at TIMESTAMPTZ yes β€” β€” β€”
acknowledged_by UUID yes β€” β€” β€”
notification_sent BOOLEAN no FALSE β€” β€”
notification_channels JSONB no '[]'::jsonb β€” β€”
created_at TIMESTAMPTZ no NOW() β€” β€”
updated_at TIMESTAMPTZ no NOW() β€” β€”
branch_id UUID yes β€” FK branches.id

inventory_movements

  • Domain: billing Β· Feature gate: #[cfg(feature = "billing")] Β· Migration: 6.5.23-branch-scope-cleanup
  • Rust source: botschema/src/billing/inventory.rs
Column SQL type Null Default Key References
id UUID no gen_random_uuid() PK β€”
org_id UUID no β€” FK organizations.org_id
bot_id UUID no β€” β€” β€”
product_id UUID no β€” FK products.id
movement_type VARCHAR(255) no β€” β€” β€”
quantity INTEGER no β€” β€” β€”
reference_type VARCHAR(255) yes β€” β€” β€”
reference_id UUID yes β€” β€” β€”
notes TEXT yes β€” β€” β€”
created_by UUID yes β€” β€” β€”
created_at TIMESTAMPTZ no NOW() β€” β€”
branch_id UUID yes β€” FK branches.id

Drift: in migrations only: item_id

pos_sales

  • Domain: billing Β· Feature gate: #[cfg(feature = "billing")] Β· Migration: 6.5.23-branch-scope-cleanup
  • Rust source: botschema/src/billing/pos.rs
Column SQL type Null Default Key References
id UUID no gen_random_uuid() PK β€”
bot_id UUID no β€” β€” β€”
session_id UUID no β€” FK pos_sessions.id
sale_number INTEGER no β€” β€” β€”
items JSONB no β€” β€” β€”
subtotal NUMERIC(12,2) no β€” β€” β€”
discount NUMERIC(12,2) yes β€” β€” β€”
tax NUMERIC(12,2) yes β€” β€” β€”
total NUMERIC(12,2) no β€” β€” β€”
payment_method VARCHAR(50) no β€” β€” β€”
nfse_id UUID yes β€” β€” β€”
created_at TIMESTAMPTZ no NOW() β€” β€”
branch_id UUID yes β€” FK branches.id

pos_sessions

  • Domain: billing Β· Feature gate: #[cfg(feature = "billing")] Β· Migration: 6.5.23-branch-scope-cleanup
  • Rust source: botschema/src/billing/pos.rs
Column SQL type Null Default Key References
id UUID no gen_random_uuid() PK β€”
bot_id UUID no β€” β€” β€”
branch_id UUID no β€” FK branches.id
operator_id UUID no β€” β€” β€”
started_at TIMESTAMPTZ no NOW() β€” β€”
closed_at TIMESTAMPTZ yes β€” β€” β€”
opening_amount NUMERIC(12,2) no 0 β€” β€”
closing_amount NUMERIC(12,2) yes β€” β€” β€”
status VARCHAR(20) no 'open' β€” β€”

price_list_items

  • Domain: billing Β· Feature gate: #[cfg(feature = "billing")] Β· Migration: 6.5.15.1-consolidated
  • Rust source: botschema/src/billing/catalog.rs
Column SQL type Null Default Key References
id UUID no gen_random_uuid() PK β€”
price_list_id UUID no β€” FK price_lists.id
product_id UUID yes β€” FK products.id
service_id UUID yes β€” FK services.id
price NUMERIC no β€” β€” β€”
min_quantity INTEGER no 1 β€” β€”
created_at TIMESTAMPTZ no NOW() β€” β€”