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() โ€” โ€”