Data model
Generated at build time from 0001_init.sql 0002_search.sql 0003_email_outbox_lease.sql 0004_ticket_down_intervals.sql 0005_idempotency_keys.sql 0006_search_keyed.sql 0007_activity_message_id.sql 0008_google_contacts.sql in packages/db/migrations(45 tables) and workers/auth/migrations. Only cemco-api reads and writes the CRM database; everything else goes through operations.
Conventions
- Ids are UUID text. Money is integer cents. Days are
YYYY-MM-DD, instants are ISO 8601 UTC text. - Booleans are
0/1; lists are JSON text. Columns are snake_case; the API is camelCase. - Every foreign key has an index. Every write appends to
audit_log. - Search uses the FTS5 table
search_index, kept current by triggers. - A new change is a new numbered migration file. Never edit a migration that has been applied.
System: staff users
users
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
email | TEXT | NOT NULL COLLATE NOCASE UNIQUE |
name | TEXT | NOT NULL |
role | TEXT | NOT NULL DEFAULT 'viewer' CHECK (role IN ('admin', 'editor', 'viewer')) |
active | INTEGER | NOT NULL DEFAULT 1 CHECK (active IN (0, 1)) |
auth_user_id | TEXT | UNIQUE |
last_seen_at | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Customers
accounts
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
name | TEXT | NOT NULL |
normalized_name | TEXT | NOT NULL |
segment | TEXT | NOT NULL DEFAULT 'concrete_producer' CHECK (segment IN ('concrete_producer', 'multiservice')) |
status | TEXT | NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'prospect', 'inactive')) |
phone | TEXT | |
website | TEXT | |
hq_line1 | TEXT | |
hq_line2 | TEXT | |
hq_city | TEXT | |
hq_state | TEXT | |
hq_postal_code | TEXT | |
hq_country | TEXT | |
hubspot_company_id | TEXT | UNIQUE |
owner_user_id | TEXT | references users.id ON DELETE SET NULL |
notes | TEXT | |
last_contacted_at | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_accounts_normalized_name (normalized_name) idx_accounts_owner (owner_user_id) idx_accounts_status (status) idx_accounts_last_contacted (last_contacted_at)
contacts
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
account_id | TEXT | references accounts.id NOT NULL ON DELETE CASCADE |
first_name | TEXT | NOT NULL |
last_name | TEXT | NOT NULL DEFAULT '' |
role | TEXT | |
email | TEXT | COLLATE NOCASE |
mobile | TEXT | |
phone | TEXT | |
preferred_channel | TEXT | NOT NULL DEFAULT 'email' CHECK (preferred_channel IN ('email', 'phone', 'text')) |
is_primary | INTEGER | NOT NULL DEFAULT 0 CHECK (is_primary IN (0, 1)) |
hubspot_contact_id | TEXT | UNIQUE |
notes | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_contacts_account (account_id) unique idx_contacts_email_unique (email) WHERE email IS NOT NULL
sites
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
account_id | TEXT | references accounts.id NOT NULL ON DELETE CASCADE |
name | TEXT | NOT NULL |
line1 | TEXT | |
line2 | TEXT | |
city | TEXT | |
state | TEXT | |
postal_code | TEXT | |
country | TEXT | DEFAULT 'US' |
latitude | REAL | |
longitude | REAL | |
power_source | TEXT | |
water_source | TEXT | |
active_from | TEXT | |
active_to | TEXT | |
notes | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_sites_account (account_id) idx_sites_state (state)
site_readiness
| Column | Type | Constraints |
|---|---|---|
site_id | TEXT | references sites.id NOT NULL ON DELETE CASCADE |
item | TEXT | NOT NULL CHECK (item IN ('pad', 'power', 'water', 'access', 'aggregate_supply')) |
confirmed | INTEGER | NOT NULL DEFAULT 0 CHECK (confirmed IN (0, 1)) |
confirmed_on | TEXT | |
confirmed_by_user_id | TEXT | references users.id ON DELETE SET NULL |
confirmed_by_name | TEXT | |
note | TEXT | |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Table constraints: PRIMARY KEY (site_id, item)
Indexes: idx_site_readiness_user (confirmed_by_user_id)
Products (equipment price list)
products
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
sku | TEXT | NOT NULL UNIQUE |
name | TEXT | NOT NULL |
category | TEXT | NOT NULL CHECK (category IN ('plant', 'mixer', 'accessory', 'option')) |
model | TEXT | |
machine_type | TEXT | CHECK (machine_type IS NULL OR machine_type IN ('plant', 'mixer', 'silo', 'feeder', 'power_pack')) |
description | TEXT | |
price_cents | INTEGER | NOT NULL CHECK (price_cents >= 0) |
price_list | TEXT | NOT NULL DEFAULT '2026.11' |
active | INTEGER | NOT NULL DEFAULT 1 CHECK (active IN (0, 1)) |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_products_category (category)
Documents (bytes live in R2 bucket cemco-documents)
documents
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
kind | TEXT | NOT NULL CHECK (kind IN ('signed_quote', 'quote', 'purchase_order', 'drawing', 'manual', 'inspection_report', 'photo', 'training_record', 'invoice', 'email_attachment', 'export', 'other')) |
title | TEXT | NOT NULL |
filename | TEXT | NOT NULL |
content_type | TEXT | NOT NULL DEFAULT 'application/octet-stream' |
size_bytes | INTEGER | NOT NULL DEFAULT 0 |
status | TEXT | NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'stored')) |
r2_key | TEXT | NOT NULL UNIQUE |
sha256 | TEXT | |
account_id | TEXT | references accounts.id ON DELETE SET NULL |
customer_visible | INTEGER | NOT NULL DEFAULT 0 CHECK (customer_visible IN (0, 1)) |
source | TEXT | NOT NULL DEFAULT 'upload' CHECK (source IN ('upload', 'email', 'portal', 'system', 'import')) |
uploaded_by_user_id | TEXT | |
uploaded_by_name | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_documents_account (account_id) idx_documents_kind (kind)
document_links
| Column | Type | Constraints |
|---|---|---|
document_id | TEXT | references documents.id NOT NULL ON DELETE CASCADE |
entity_type | TEXT | NOT NULL |
entity_id | TEXT | NOT NULL |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Table constraints: PRIMARY KEY (document_id, entity_type, entity_id)
Indexes: idx_document_links_entity (entity_type, entity_id)
Orders
orders
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
order_number | TEXT | NOT NULL UNIQUE |
account_id | TEXT | references accounts.id NOT NULL ON DELETE RESTRICT |
site_id | TEXT | references sites.id ON DELETE SET NULL |
title | TEXT | |
stage | TEXT | NOT NULL DEFAULT 'received' CHECK (stage IN ('received', 'in_build', 'ready_to_ship', 'shipped', 'delivered', 'set_up', 'commissioned', 'trained', 'closed')) |
signed_quote_document_id | TEXT | references documents.id ON DELETE SET NULL |
signed_quote_received_on | TEXT | |
total_cents | INTEGER | NOT NULL DEFAULT 0 CHECK (total_cents >= 0) |
balance_remaining_cents | INTEGER | CHECK (balance_remaining_cents IS NULL OR balance_remaining_cents >= 0) |
is_valid | INTEGER | GENERATED ALWAYS AS ( signed_quote_document_id IS NOT NULL AND signed_quote_received_on IS NOT NULL AND balance_remaining_cents IS NOT NULL ) STORED |
financing_partner | TEXT | NOT NULL DEFAULT 'none' CHECK (financing_partner IN ('none', 'commercial_capital', 'northland_capital', 'other')) |
financing_status | TEXT | NOT NULL DEFAULT 'not_applicable' CHECK (financing_status IN ('not_applicable', 'pending', 'approved', 'declined', 'funded')) |
financing_notes | TEXT | |
po_number | TEXT | |
expected_ship_on | TEXT | |
owner_user_id | TEXT | references users.id ON DELETE SET NULL |
notes | TEXT | |
received_on | TEXT | |
in_build_on | TEXT | |
ready_to_ship_on | TEXT | |
shipped_on | TEXT | |
delivered_on | TEXT | |
set_up_on | TEXT | |
commissioned_on | TEXT | |
trained_on | TEXT | |
closed_on | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Table constraints: CHECK (stage = 'received' OR (signed_quote_document_id IS NOT NULL AND signed_quote_received_on IS NOT NULL AND balance_remaining_cents IS NOT NULL))
Indexes: idx_orders_account (account_id) idx_orders_site (site_id) idx_orders_stage (stage) idx_orders_signed_quote (signed_quote_document_id) idx_orders_owner (owner_user_id) idx_orders_valid (is_valid)
order_lines
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
order_id | TEXT | references orders.id NOT NULL ON DELETE CASCADE |
product_id | TEXT | references products.id ON DELETE SET NULL |
sku | TEXT | |
description | TEXT | NOT NULL |
quantity | INTEGER | NOT NULL DEFAULT 1 CHECK (quantity >= 1) |
unit_price_cents | INTEGER | NOT NULL DEFAULT 0 CHECK (unit_price_cents >= 0) |
total_cents | INTEGER | NOT NULL DEFAULT 0 CHECK (total_cents >= 0) |
position | INTEGER | NOT NULL DEFAULT 0 |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_order_lines_order (order_id) idx_order_lines_product (product_id)
order_events
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
order_id | TEXT | references orders.id NOT NULL ON DELETE CASCADE |
from_stage | TEXT | |
to_stage | TEXT | NOT NULL |
occurred_on | TEXT | NOT NULL |
note | TEXT | |
actor_user_id | TEXT | |
actor_name | TEXT | NOT NULL |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_order_events_order (order_id)
Installed base
machines
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
serial_number | TEXT | NOT NULL UNIQUE |
serial_normalized | TEXT | NOT NULL |
type | TEXT | NOT NULL CHECK (type IN ('plant', 'mixer', 'silo', 'feeder', 'power_pack')) |
model | TEXT | NOT NULL |
configuration | TEXT | |
options | TEXT | NOT NULL DEFAULT '[]' |
account_id | TEXT | references accounts.id NOT NULL ON DELETE RESTRICT |
site_id | TEXT | references sites.id ON DELETE SET NULL |
order_id | TEXT | references orders.id ON DELETE SET NULL |
product_id | TEXT | references products.id ON DELETE SET NULL |
status | TEXT | NOT NULL DEFAULT 'in_build' CHECK (status IN ('in_build', 'in_transit', 'operating', 'down', 'idle', 'retired')) |
built_on | TEXT | |
shipped_on | TEXT | |
commissioned_on | TEXT | |
warranty_start | TEXT | |
warranty_end | TEXT | |
notes | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_machines_serial_normalized (serial_normalized) idx_machines_account (account_id) idx_machines_site (site_id) idx_machines_order (order_id) idx_machines_product (product_id) idx_machines_status (status) idx_machines_warranty_end (warranty_end)
machine_locations
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
machine_id | TEXT | references machines.id NOT NULL ON DELETE CASCADE |
site_id | TEXT | references sites.id NOT NULL ON DELETE CASCADE |
moved_in_on | TEXT | NOT NULL |
moved_out_on | TEXT | |
note | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_machine_locations_machine (machine_id) idx_machine_locations_site (site_id)
machine_owners
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
machine_id | TEXT | references machines.id NOT NULL ON DELETE CASCADE |
account_id | TEXT | references accounts.id NOT NULL ON DELETE RESTRICT |
from_date | TEXT | NOT NULL |
to_date | TEXT | |
note | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_machine_owners_machine (machine_id) idx_machine_owners_account (account_id)
service_plans
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
machine_id | TEXT | references machines.id NOT NULL ON DELETE CASCADE |
name | TEXT | NOT NULL |
interval_days | INTEGER | NOT NULL CHECK (interval_days >= 1) |
last_done_on | TEXT | |
next_due_on | TEXT | NOT NULL |
recommended_part_ids | TEXT | NOT NULL DEFAULT '[]' |
notes | TEXT | |
active | INTEGER | NOT NULL DEFAULT 1 CHECK (active IN (0, 1)) |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_service_plans_machine (machine_id) idx_service_plans_next_due (next_due_on)
service_contracts
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
machine_id | TEXT | references machines.id NOT NULL ON DELETE CASCADE |
account_id | TEXT | references accounts.id NOT NULL ON DELETE RESTRICT |
plan_name | TEXT | NOT NULL |
starts_on | TEXT | NOT NULL |
renews_on | TEXT | NOT NULL |
price_cents | INTEGER | NOT NULL DEFAULT 0 CHECK (price_cents >= 0) |
status | TEXT | NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'expired', 'cancelled')) |
notes | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_service_contracts_machine (machine_id) idx_service_contracts_account (account_id) idx_service_contracts_renews (renews_on)
training_records
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
machine_id | TEXT | references machines.id NOT NULL ON DELETE CASCADE |
order_id | TEXT | references orders.id ON DELETE SET NULL |
set_up_on | TEXT | |
first_batch_on | TEXT | |
trained_on | TEXT | NOT NULL |
trainer_name | TEXT | NOT NULL |
trainees | TEXT | NOT NULL DEFAULT '[]' |
topics | TEXT | |
punch_list | TEXT | NOT NULL DEFAULT '[]' |
customer_signoff_name | TEXT | |
customer_signed_on | TEXT | |
signoff_document_id | TEXT | references documents.id ON DELETE SET NULL |
notes | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_training_records_machine (machine_id) idx_training_records_order (order_id) idx_training_records_document (signoff_document_id)
Tasks (before check-ins, which point at them)
tasks
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
type | TEXT | NOT NULL DEFAULT 'task' CHECK (type IN ('task', 'call', 'visit', 'delivery', 'commissioning', 'service', 'check_in')) |
title | TEXT | NOT NULL |
notes | TEXT | |
status | TEXT | NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'done', 'cancelled')) |
due_on | TEXT | NOT NULL |
starts_at | TEXT | |
ends_at | TEXT | |
location | TEXT | |
assigned_to_user_id | TEXT | references users.id ON DELETE SET NULL |
account_id | TEXT | references accounts.id ON DELETE CASCADE |
contact_id | TEXT | references contacts.id ON DELETE SET NULL |
order_id | TEXT | references orders.id ON DELETE SET NULL |
machine_id | TEXT | references machines.id ON DELETE SET NULL |
ticket_id | TEXT | |
site_id | TEXT | references sites.id ON DELETE SET NULL |
check_in_id | TEXT | |
google_event_id | TEXT | |
google_calendar_id | TEXT | |
sync_state | TEXT | NOT NULL DEFAULT 'pending' CHECK (sync_state IN ('not_synced', 'pending', 'synced', 'error')) |
synced_at | TEXT | |
sync_error | TEXT | |
completed_at | TEXT | |
created_by_user_id | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_tasks_assigned (assigned_to_user_id) idx_tasks_account (account_id) idx_tasks_contact (contact_id) idx_tasks_order (order_id) idx_tasks_machine (machine_id) idx_tasks_ticket (ticket_id) idx_tasks_site (site_id) idx_tasks_check_in (check_in_id) idx_tasks_due (status, due_on) idx_tasks_sync (sync_state) unique idx_tasks_google_event (google_event_id) WHERE google_event_id IS NOT NULL
calendar_tombstones
Google events to remove after a synced task was deleted.
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
task_id | TEXT | NOT NULL |
google_event_id | TEXT | NOT NULL |
google_calendar_id | TEXT | |
assigned_to_user_id | TEXT | references users.id ON DELETE SET NULL |
title | TEXT | |
deleted_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_calendar_tombstones_user (assigned_to_user_id)
check_ins
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
account_id | TEXT | references accounts.id NOT NULL ON DELETE CASCADE |
machine_id | TEXT | references machines.id ON DELETE CASCADE |
order_id | TEXT | references orders.id ON DELETE SET NULL |
kind | TEXT | NOT NULL CHECK (kind IN ('day_30', 'day_90', 'day_365', 'pre_season', 'ad_hoc')) |
due_on | TEXT | NOT NULL |
status | TEXT | NOT NULL DEFAULT 'scheduled' CHECK (status IN ('scheduled', 'completed', 'skipped')) |
completed_on | TEXT | |
outcome | TEXT | |
task_id | TEXT | references tasks.id ON DELETE SET NULL |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_check_ins_account (account_id) idx_check_ins_machine (machine_id) idx_check_ins_order (order_id) idx_check_ins_task (task_id) idx_check_ins_due (status, due_on) unique idx_check_ins_auto_unique (order_id, machine_id, kind) WHERE kind IN ('day_30', 'day_90', 'day_365') AND order_id IS NOT NULL AND machine_id IS NOT NULL
Parts and stock
parts
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
part_number | TEXT | NOT NULL UNIQUE COLLATE NOCASE |
description | TEXT | NOT NULL |
category | TEXT | |
unit | TEXT | NOT NULL DEFAULT 'each' |
price_cents | INTEGER | NOT NULL DEFAULT 0 CHECK (price_cents >= 0) |
price_list_date | TEXT | NOT NULL |
fits_models | TEXT | NOT NULL DEFAULT '[]' |
on_hand | INTEGER | NOT NULL DEFAULT 0 |
reorder_point | INTEGER | NOT NULL DEFAULT 0 CHECK (reorder_point >= 0) |
reorder_quantity | INTEGER | NOT NULL DEFAULT 0 CHECK (reorder_quantity >= 0) |
bin_location | TEXT | |
recommended_spare | INTEGER | NOT NULL DEFAULT 0 CHECK (recommended_spare IN (0, 1)) |
active | INTEGER | NOT NULL DEFAULT 1 CHECK (active IN (0, 1)) |
low_stock_alerted_at | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_parts_category (category) idx_parts_price_list_date (price_list_date)
Service
tickets
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
ticket_number | TEXT | NOT NULL UNIQUE |
account_id | TEXT | references accounts.id NOT NULL ON DELETE RESTRICT |
machine_id | TEXT | references machines.id NOT NULL ON DELETE RESTRICT |
contact_id | TEXT | references contacts.id ON DELETE SET NULL |
title | TEXT | NOT NULL |
description | TEXT | |
category | TEXT | NOT NULL DEFAULT 'other' CHECK (category IN ('mechanical', 'electrical', 'controls', 'hydraulic', 'pneumatic', 'structural', 'calibration', 'operator_training', 'other')) |
priority | TEXT | NOT NULL DEFAULT 'normal' CHECK (priority IN ('low', 'normal', 'high', 'down')) |
status | TEXT | NOT NULL DEFAULT 'new' CHECK (status IN ('new', 'diagnosing', 'parts_on_order', 'scheduled', 'waiting_on_customer', 'resolved', 'follow_up_complete')) |
root_cause | TEXT | CHECK (root_cause IS NULL OR root_cause IN ('component_failure', 'manufacturing_defect', 'wear', 'operator_error', 'installation', 'shipping_damage', 'environment', 'design', 'unknown')) |
resolution | TEXT | |
source | TEXT | NOT NULL DEFAULT 'staff' CHECK (source IN ('staff', 'portal', 'email', 'agent')) |
assigned_to_user_id | TEXT | references users.id ON DELETE SET NULL |
is_warranty | INTEGER | NOT NULL DEFAULT 0 CHECK (is_warranty IN (0, 1)) |
onsite_hours | REAL | NOT NULL DEFAULT 0 |
travel_hours | REAL | NOT NULL DEFAULT 0 |
travel_miles | REAL | NOT NULL DEFAULT 0 |
opened_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
scheduled_for | TEXT | |
resolved_at | TEXT | |
down_since | TEXT | |
down_until | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_tickets_account (account_id) idx_tickets_machine (machine_id) idx_tickets_contact (contact_id) idx_tickets_assigned (assigned_to_user_id) idx_tickets_status (status, priority) idx_tickets_opened (opened_at)
parts_orders
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
order_number | TEXT | NOT NULL UNIQUE |
account_id | TEXT | references accounts.id NOT NULL ON DELETE RESTRICT |
contact_id | TEXT | references contacts.id ON DELETE SET NULL |
machine_id | TEXT | references machines.id ON DELETE SET NULL |
ticket_id | TEXT | references tickets.id ON DELETE SET NULL |
status | TEXT | NOT NULL DEFAULT 'quote' CHECK (status IN ('quote', 'ordered', 'shipped', 'delivered', 'cancelled')) |
subtotal_cents | INTEGER | NOT NULL DEFAULT 0 CHECK (subtotal_cents >= 0) |
shipping_cents | INTEGER | NOT NULL DEFAULT 0 CHECK (shipping_cents >= 0) |
tax_cents | INTEGER | NOT NULL DEFAULT 0 CHECK (tax_cents >= 0) |
total_cents | INTEGER | NOT NULL DEFAULT 0 CHECK (total_cents >= 0) |
quoted_on | TEXT | NOT NULL |
quote_valid_until | TEXT | |
ordered_on | TEXT | |
shipped_on | TEXT | |
delivered_on | TEXT | |
carrier | TEXT | |
tracking_number | TEXT | |
ship_to_name | TEXT | |
ship_to_address | TEXT | |
customer_po | TEXT | |
notes | TEXT | |
created_by_user_id | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_parts_orders_account (account_id) idx_parts_orders_contact (contact_id) idx_parts_orders_machine (machine_id) idx_parts_orders_ticket (ticket_id) idx_parts_orders_status (status)
parts_order_lines
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
parts_order_id | TEXT | references parts_orders.id NOT NULL ON DELETE CASCADE |
part_id | TEXT | references parts.id NOT NULL ON DELETE RESTRICT |
part_number | TEXT | NOT NULL |
description | TEXT | NOT NULL |
quantity | INTEGER | NOT NULL DEFAULT 1 CHECK (quantity >= 1) |
unit_price_cents | INTEGER | NOT NULL DEFAULT 0 CHECK (unit_price_cents >= 0) |
total_cents | INTEGER | NOT NULL DEFAULT 0 CHECK (total_cents >= 0) |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_parts_order_lines_order (parts_order_id) idx_parts_order_lines_part (part_id)
stock_movements
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
part_id | TEXT | references parts.id NOT NULL ON DELETE RESTRICT |
type | TEXT | NOT NULL CHECK (type IN ('receive', 'adjust', 'ship', 'return')) |
quantity | INTEGER | NOT NULL CHECK (quantity <> 0) |
balance_after | INTEGER | NOT NULL |
reason | TEXT | |
parts_order_id | TEXT | references parts_orders.id ON DELETE SET NULL |
ticket_id | TEXT | references tickets.id ON DELETE SET NULL |
unit_cost_cents | INTEGER | |
actor_user_id | TEXT | |
actor_name | TEXT | NOT NULL |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_stock_movements_part (part_id, created_at) idx_stock_movements_parts_order (parts_order_id) idx_stock_movements_ticket (ticket_id)
ticket_parts
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
ticket_id | TEXT | references tickets.id NOT NULL ON DELETE CASCADE |
part_id | TEXT | references parts.id NOT NULL ON DELETE RESTRICT |
part_number | TEXT | NOT NULL |
description | TEXT | NOT NULL |
quantity | INTEGER | NOT NULL DEFAULT 1 CHECK (quantity >= 1) |
unit_price_cents | INTEGER | NOT NULL DEFAULT 0 CHECK (unit_price_cents >= 0) |
covered_by_warranty | INTEGER | NOT NULL DEFAULT 0 CHECK (covered_by_warranty IN (0, 1)) |
stock_movement_id | TEXT | references stock_movements.id ON DELETE SET NULL |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_ticket_parts_ticket (ticket_id) idx_ticket_parts_part (part_id) idx_ticket_parts_movement (stock_movement_id)
ticket_time_entries
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
ticket_id | TEXT | references tickets.id NOT NULL ON DELETE CASCADE |
work_date | TEXT | NOT NULL |
onsite_hours | REAL | NOT NULL DEFAULT 0 |
travel_hours | REAL | NOT NULL DEFAULT 0 |
travel_miles | REAL | NOT NULL DEFAULT 0 |
technician_name | TEXT | NOT NULL |
note | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_ticket_time_entries_ticket (ticket_id)
warranty_claims
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
claim_number | TEXT | NOT NULL UNIQUE |
ticket_id | TEXT | references tickets.id NOT NULL ON DELETE CASCADE |
machine_id | TEXT | references machines.id NOT NULL ON DELETE RESTRICT |
account_id | TEXT | references accounts.id NOT NULL ON DELETE RESTRICT |
status | TEXT | NOT NULL DEFAULT 'submitted' CHECK (status IN ('submitted', 'approved', 'denied', 'credited')) |
description | TEXT | |
amount_claimed_cents | INTEGER | NOT NULL DEFAULT 0 CHECK (amount_claimed_cents >= 0) |
credit_cents | INTEGER | NOT NULL DEFAULT 0 CHECK (credit_cents >= 0) |
submitted_on | TEXT | NOT NULL |
decided_on | TEXT | |
notes | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_warranty_claims_ticket (ticket_id) idx_warranty_claims_machine (machine_id) idx_warranty_claims_account (account_id)
Activity
activities
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
type | TEXT | NOT NULL CHECK (type IN ('call', 'email', 'text', 'visit', 'note', 'system')) |
direction | TEXT | CHECK (direction IS NULL OR direction IN ('outbound', 'inbound')) |
subject | TEXT | NOT NULL |
body | TEXT | |
occurred_at | TEXT | NOT NULL |
account_id | TEXT | references accounts.id NOT NULL ON DELETE CASCADE |
contact_id | TEXT | references contacts.id ON DELETE SET NULL |
order_id | TEXT | references orders.id ON DELETE SET NULL |
machine_id | TEXT | references machines.id ON DELETE SET NULL |
ticket_id | TEXT | references tickets.id ON DELETE SET NULL |
external_ref | TEXT | |
external_thread_id | TEXT | |
from_address | TEXT | |
to_addresses | TEXT | NOT NULL DEFAULT '[]' |
duration_minutes | INTEGER | |
logged_by_user_id | TEXT | |
logged_by_name | TEXT | NOT NULL |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
rfc822_message_id | TEXT |
Indexes: unique idx_activities_external_ref (external_ref) WHERE external_ref IS NOT NULL idx_activities_account (account_id, occurred_at) idx_activities_contact (contact_id) idx_activities_order (order_id) idx_activities_machine (machine_id) idx_activities_ticket (ticket_id) unique idx_activities_rfc822_message_id (rfc822_message_id) WHERE rfc822_message_id IS NOT NULL
activity_documents
| Column | Type | Constraints |
|---|---|---|
activity_id | TEXT | references activities.id NOT NULL ON DELETE CASCADE |
document_id | TEXT | references documents.id NOT NULL ON DELETE CASCADE |
Table constraints: PRIMARY KEY (activity_id, document_id)
Indexes: idx_activity_documents_document (document_id)
Opportunities
opportunities
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
account_id | TEXT | references accounts.id NOT NULL ON DELETE CASCADE |
title | TEXT | NOT NULL |
description | TEXT | |
product_id | TEXT | references products.id ON DELETE SET NULL |
machine_id | TEXT | references machines.id ON DELETE SET NULL |
estimated_value_cents | INTEGER | CHECK (estimated_value_cents IS NULL OR estimated_value_cents >= 0) |
status | TEXT | NOT NULL DEFAULT 'open' CHECK (status IN ('open', 'handed_to_sales', 'won', 'lost')) |
handed_to_sales_on | TEXT | |
sales_contact | TEXT | |
notes | TEXT | |
created_by_user_id | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
updated_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_opportunities_account (account_id) idx_opportunities_product (product_id) idx_opportunities_machine (machine_id) idx_opportunities_status (status)
Import
import_runs
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
entity | TEXT | NOT NULL CHECK (entity IN ('accounts', 'contacts', 'sites', 'products', 'parts', 'machines')) |
source | TEXT | NOT NULL DEFAULT 'google_sheet' |
source_name | TEXT | |
status | TEXT | NOT NULL DEFAULT 'dry_run' CHECK (status IN ('dry_run', 'applying', 'applied', 'failed')) |
mapping | TEXT | NOT NULL DEFAULT '{}' |
columns | TEXT | NOT NULL DEFAULT '[]' |
defaults | TEXT | NOT NULL DEFAULT '{}' |
on_duplicate | TEXT | NOT NULL DEFAULT 'skip' CHECK (on_duplicate IN ('skip', 'update')) |
total_rows | INTEGER | NOT NULL DEFAULT 0 |
create_count | INTEGER | NOT NULL DEFAULT 0 |
update_count | INTEGER | NOT NULL DEFAULT 0 |
duplicate_count | INTEGER | NOT NULL DEFAULT 0 |
error_count | INTEGER | NOT NULL DEFAULT 0 |
created_by_user_id | TEXT | |
created_by_name | TEXT | NOT NULL |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
applied_at | TEXT |
Indexes: idx_import_runs_status (status)
import_rows
| Column | Type | Constraints |
|---|---|---|
run_id | TEXT | references import_runs.id NOT NULL ON DELETE CASCADE |
row_number | INTEGER | NOT NULL |
action | TEXT | NOT NULL CHECK (action IN ('create', 'update', 'skip_duplicate', 'error')) |
data | TEXT | NOT NULL DEFAULT '{}' |
errors | TEXT | NOT NULL DEFAULT '[]' |
duplicate_of_id | TEXT | |
duplicate_of_name | TEXT | |
result_id | TEXT |
Table constraints: PRIMARY KEY (run_id, row_number)
Portal
customer_users
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
auth_user_id | TEXT | NOT NULL UNIQUE |
account_id | TEXT | references accounts.id NOT NULL ON DELETE CASCADE |
contact_id | TEXT | references contacts.id ON DELETE SET NULL |
email | TEXT | NOT NULL COLLATE NOCASE UNIQUE |
name | TEXT | NOT NULL |
active | INTEGER | NOT NULL DEFAULT 1 CHECK (active IN (0, 1)) |
last_seen_at | TEXT | |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_customer_users_account (account_id) idx_customer_users_contact (contact_id)
portal_invites
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
account_id | TEXT | references accounts.id NOT NULL ON DELETE CASCADE |
contact_id | TEXT | references contacts.id ON DELETE SET NULL |
email | TEXT | NOT NULL COLLATE NOCASE |
name | TEXT | NOT NULL |
token_hash | TEXT | NOT NULL UNIQUE |
status | TEXT | NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'accepted', 'revoked', 'expired')) |
expires_at | TEXT | NOT NULL |
invited_by_user_id | TEXT | |
invited_by_name | TEXT | NOT NULL |
accepted_at | TEXT | |
customer_user_id | TEXT | references customer_users.id ON DELETE SET NULL |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
Indexes: idx_portal_invites_account (account_id) idx_portal_invites_contact (contact_id) idx_portal_invites_customer_user (customer_user_id) idx_portal_invites_email (email, status)
Calendar feeds, audit log, email outbox, counters
calendar_feeds
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
user_id | TEXT | references users.id NOT NULL UNIQUE ON DELETE CASCADE |
token | TEXT | NOT NULL UNIQUE |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
last_accessed_at | TEXT |
audit_log
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
actor_kind | TEXT | NOT NULL CHECK (actor_kind IN ('staff', 'customer', 'agent', 'system')) |
actor_user_id | TEXT | NOT NULL |
actor_email | TEXT | NOT NULL |
actor_name | TEXT | NOT NULL |
operation | TEXT | NOT NULL |
entity_type | TEXT | |
entity_id | TEXT | |
account_id | TEXT | |
summary | TEXT | |
detail | TEXT | |
request_id | TEXT |
Indexes: idx_audit_log_at (at) idx_audit_log_entity (entity_type, entity_id) idx_audit_log_account (account_id, at) idx_audit_log_actor (actor_user_id, at) idx_audit_log_operation (operation, at)
email_outbox
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
template | TEXT | NOT NULL |
to_address | TEXT | NOT NULL |
subject | TEXT | NOT NULL |
body_text | TEXT | NOT NULL |
body_html | TEXT | |
status | TEXT | NOT NULL DEFAULT 'queued' CHECK (status IN ('queued', 'sent', 'failed', 'skipped')) |
account_id | TEXT | references accounts.id ON DELETE SET NULL |
entity_type | TEXT | |
entity_id | TEXT | |
dedupe_key | TEXT | UNIQUE |
error | TEXT | |
attempts | INTEGER | NOT NULL DEFAULT 0 |
created_at | TEXT | NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')) |
sent_at | TEXT | |
lease_until | TEXT |
Indexes: idx_email_outbox_status (status, created_at) idx_email_outbox_account (account_id) idx_email_outbox_entity (entity_type, entity_id)
counters
Sequences for order, ticket, parts order and claim numbers.
| Column | Type | Constraints |
|---|---|---|
name | TEXT | PRIMARY KEY |
value | INTEGER | NOT NULL DEFAULT 0 |
Other
ticket_down_intervals
Earlier downtime intervals of a ticket. tickets.down_since/down_until hold the current (or last) interval; when a resolved down ticket is reopened as down, its finished interval is moved here first so the time the machine ran between the two is not counted as downtime.
| Column | Type | Constraints |
|---|---|---|
id | TEXT | PRIMARY KEY |
ticket_id | TEXT | references tickets.id NOT NULL ON DELETE CASCADE |
machine_id | TEXT | references machines.id NOT NULL ON DELETE RESTRICT |
account_id | TEXT | references accounts.id NOT NULL ON DELETE RESTRICT |
started_at | TEXT | NOT NULL |
ended_at | TEXT | NOT NULL |
created_at | TEXT | NOT NULL |
Indexes: idx_ticket_down_intervals_ticket (ticket_id) idx_ticket_down_intervals_machine (machine_id) idx_ticket_down_intervals_account (account_id)
idempotency_keys
Idempotency keys for POST /v1/ops/{name}. A client that may send the same write twice (the app's offline outbox after a dropped connection, two tabs replaying the same outbox) sends an Idempotency-Key header; the first request claims the key, and a repeat gets the stored answer instead of applying the write again. Keys belong to the caller and are purged after 7 days.
| Column | Type | Constraints |
|---|---|---|
actor_id | TEXT | NOT NULL |
key | TEXT | NOT NULL |
operation | TEXT | NOT NULL |
state | TEXT | NOT NULL CHECK (state IN ('pending', 'done')) |
response | TEXT | |
created_at | TEXT | NOT NULL |
Table constraints: PRIMARY KEY (actor_id, key)
Indexes: idx_idempotency_keys_created (created_at)
search_indexfts5 virtual table
Full-text search (FTS5) over the records the one search box covers (FR-26). Kept current by triggers; `reindexSearch()` in @cemco/db rebuilds it by touching rows.
| Column | Type | Constraints |
|---|---|---|
entity_type | text | UNINDEXED |
entity_id | text | UNINDEXED |
account_id | text | UNINDEXED |
title | text | |
subtitle | text | |
body | text |
Table constraints: content = 'search_docs' content_rowid = 'id' tokenize = 'unicode61 remove_diacritics 2' prefix = '2 3 4'
google_contact_links
Two-way Google Contacts sync, per staff user. A CRM contact is linked to one Google contact (resource name) in each connected user's Google account. `pushed_at` is the contact's updated_at last sent to or taken from Google, so a later CRM edit is pushed again. state 'removed': the user deleted it in Google; it is not pushed again.
| Column | Type | Constraints |
|---|---|---|
user_id | TEXT | references users.id NOT NULL ON DELETE CASCADE |
contact_id | TEXT | references contacts.id NOT NULL ON DELETE CASCADE |
resource_name | TEXT | NOT NULL |
etag | TEXT | |
state | TEXT | NOT NULL DEFAULT 'linked' CHECK (state IN ('linked', 'removed')) |
pushed_at | TEXT | |
synced_at | TEXT | NOT NULL |
Table constraints: PRIMARY KEY (user_id, contact_id)
Indexes: unique idx_google_contact_links_resource (user_id, resource_name)
google_contact_sync
| Column | Type | Constraints |
|---|---|---|
user_id | TEXT | references users.id PRIMARY KEY ON DELETE CASCADE |
sync_token | TEXT | |
last_synced_at | TEXT | |
last_error | TEXT |
Now the indexed text lives in an ordinary table, search_docs, unique on (entity_type,
search_docs
| Column | Type | Constraints |
|---|---|---|
id | INTEGER | PRIMARY KEY |
entity_type | TEXT | NOT NULL |
entity_id | TEXT | NOT NULL |
account_id | TEXT | |
title | TEXT | |
subtitle | TEXT | |
body | TEXT |
Table constraints: UNIQUE (entity_type, entity_id)
Auth database
cemco-auth is owned by the auth Worker and holds sign-in data only (users, sessions, API keys and OAuth clients as the auth service adds them). The CRM links to it through users.auth_user_id andcustomer_users.
auth_events
cemco-auth database. The better-auth tables (user, session, account, verification, apikey, oauth clients and tokens) are added by later migrations in this folder. This first migration adds a small sign-in event log (who signed in, refused sign-ins) for the auth build-out to write to. Nothing writes to it yet.
id TEXT at TEXT kind TEXT email TEXT detail TEXT
user
id TEXT name TEXT email TEXT emailVerified INTEGER image TEXT createdAt DATE updatedAt DATE userType TEXT disabled INTEGER lastSignInAt DATE
session
id TEXT expiresAt DATE token TEXT createdAt DATE updatedAt DATE ipAddress TEXT userAgent TEXT userId TEXT
account
id TEXT accountId TEXT providerId TEXT userId TEXT accessToken TEXT refreshToken TEXT idToken TEXT accessTokenExpiresAt DATE refreshTokenExpiresAt DATE scope TEXT password TEXT createdAt DATE updatedAt DATE
verification
id TEXT identifier TEXT value TEXT expiresAt DATE createdAt DATE updatedAt DATE
apikey
id TEXT configId TEXT name TEXT start TEXT referenceId TEXT prefix TEXT key TEXT refillInterval INTEGER refillAmount INTEGER lastRefillAt DATE enabled INTEGER rateLimitEnabled INTEGER rateLimitTimeWindow INTEGER rateLimitMax INTEGER requestCount INTEGER remaining INTEGER lastRequest DATE expiresAt DATE createdAt DATE updatedAt DATE permissions TEXT metadata TEXT
jwks
id TEXT publicKey TEXT privateKey TEXT createdAt DATE expiresAt DATE alg TEXT crv TEXT
oauthClient
id TEXT clientId TEXT clientSecret TEXT clientDiscoveryId TEXT disabled INTEGER skipConsent INTEGER enableEndSession INTEGER subjectType TEXT scopes TEXT clientCredentialsScopes TEXT userId TEXT createdAt DATE updatedAt DATE name TEXT uri TEXT icon TEXT contacts TEXT tos TEXT policy TEXT softwareId TEXT softwareVersion TEXT softwareStatement TEXT redirectUris TEXT postLogoutRedirectUris TEXT backchannelLogoutUri TEXT backchannelLogoutSessionRequired INTEGER tokenEndpointAuthMethod TEXT applicationType TEXT jwks TEXT jwksUri TEXT grantTypes TEXT responseTypes TEXT requirePKCE INTEGER dpopBoundAccessTokens INTEGER referenceId TEXT metadata TEXT
oauthResource
id TEXT identifier TEXT name TEXT accessTokenTtl INTEGER refreshTokenTtl INTEGER signingAlgorithm TEXT signingKeyId TEXT allowedScopes TEXT customClaims TEXT dpopBoundAccessTokensRequired INTEGER disabled INTEGER createdAt DATE updatedAt DATE policyVersion INTEGER metadata TEXT
oauthClientResource
id TEXT clientId TEXT resourceId TEXT metadata TEXT createdAt DATE
oauthRefreshToken
id TEXT token TEXT clientId TEXT sessionId TEXT userId TEXT referenceId TEXT authorizationCodeId TEXT resources TEXT requestedUserInfoClaims TEXT expiresAt DATE createdAt DATE revoked DATE rotatedAt DATE rotationReplayResponse TEXT rotationReplayExpiresAt DATE authTime DATE confirmation TEXT scopes TEXT
oauthAccessToken
id TEXT token TEXT clientId TEXT sessionId TEXT userId TEXT referenceId TEXT authorizationCodeId TEXT resources TEXT requestedUserInfoClaims TEXT refreshId TEXT expiresAt DATE createdAt DATE revoked DATE confirmation TEXT scopes TEXT
oauthConsent
id TEXT clientId TEXT userId TEXT referenceId TEXT resources TEXT requestedUserInfoClaims TEXT scopes TEXT createdAt DATE updatedAt DATE
oauthClientAssertion
id TEXT expiresAt DATE
rateLimit
id TEXT key TEXT count INTEGER lastRequest BIGINT