customers

Description

Customer records. A customer may have zero to many accounts (via accounts.customer_id). Supports max balance constraints and arbitrary key-value metadata.

Table Definition
CREATE TABLE customers (
    id TEXT PRIMARY KEY,
    name TEXT NOT NULL UNIQUE,
    max_balance_amount TEXT NOT NULL DEFAULT '',
    max_balance_commodity TEXT NOT NULL DEFAULT '',
    created_at TEXT DEFAULT (datetime('now'))
)

Columns

Name Type Default Nullable Children Parents Comment
created_at TEXT datetime('now') true Timestamp when the customer was created
id TEXT true accounts customer_metadata UUID primary key
max_balance_amount TEXT '' false Maximum allowed balance amount (empty = no limit)
max_balance_commodity TEXT '' false Commodity for the max balance constraint
name TEXT false Customer name (unique)

Constraints

Name Type Definition
id PRIMARY KEY PRIMARY KEY (id)
sqlite_autoindex_customers_1 PRIMARY KEY PRIMARY KEY (id)
sqlite_autoindex_customers_2 UNIQUE UNIQUE (name)

Indexes

Name Definition
sqlite_autoindex_customers_1 PRIMARY KEY (id)
sqlite_autoindex_customers_2 UNIQUE (name)

Relations

erDiagram

"accounts" }o--o| "customers" : "FOREIGN KEY (customer_id) REFERENCES customers (id) ON UPDATE NO ACTION ON DELETE NO ACTION MATCH NONE"
"accounts" }o--o| "customers" : "accounts.customer_id -> customers.id"
"customer_metadata" }o--|| "customers" : "FOREIGN KEY (customer_id) REFERENCES customers (id) ON UPDATE NO ACTION ON DELETE NO ACTION MATCH NONE"
"customer_metadata" }o--|| "customers" : "customer_metadata.customer_id -> customers.id"

"customers" {
  TEXT created_at "Timestamp when the customer was created"
  TEXT id PK "UUID primary key"
  TEXT max_balance_amount "Maximum allowed balance amount (empty = no limit)"
  TEXT max_balance_commodity "Commodity for the max balance constraint"
  TEXT name "Customer name (unique)"
}
"accounts" {
  TEXT account_id "Specific account identifier within the product"
  TEXT account_type "One of: Asset, Liability, Equity, Income, Expense"
  TEXT address "Sub-address within the account (e.g. branch). 'Pending' marks pending accounts"
  TEXT commodity FK "Commodity code (FK to commodities.code)"
  TEXT created_at "Timestamp when the account was created"
  TEXT customer_id FK "Optional owning customer (FK to customers.id). A customer may have many accounts"
  TEXT full_path "Hierarchical account path, e.g. Asset:Bank:Current:Main"
  TEXT gross_interest_rate "Gross annual interest rate as a decimal (0.045 = 4.5%)"
  TEXT id PK "UUID primary key"
  INTEGER interest_accumulator "Sub-unit fractions at extended precision (method-dependent)"
  TEXT interest_method "Interest calculation method (e.g. simple_daily)"
  INTEGER is_pending "True if this is a pending/suspense account"
  TEXT opened_at "When the account was opened"
  TEXT product "Product category within the account type"
}
"customer_metadata" {
  TEXT customer_id FK "FK to customers.id"
  TEXT id PK "UUID primary key"
  TEXT key "Metadata key"
  TEXT value "Metadata value"
}

Generated by tbls