For the complete documentation index, see llms.txt. This page is also available as Markdown.
BDR schema
BDR organizes devices and business entities into assets, with custom fields, relationships, and audit trails. Browse the schema definition and key table descriptions
This schema is currently in development. BDR (Business Data Repository) organizes data around assets: a unified combination of a device and a business entity, such as a vehicle and its driver, or a device and its sensors. IoT Query reads from BDR to expose this data for analytics. If you're interested in early access or have questions about this functionality, please contact [email protected].
BDR provides a comprehensive framework for managing organizational structures, actors, devices, assets, and their relationships in multi-tenant environments. Built on PostgreSQL 18 with the ltree and pg_trgm extensions, the schema supports hierarchical organizations, custom field definitions for any entity type, actor-based role access control with object-level restrictions, optimistic locking for concurrent edits, and complete audit trails with field-level change tracking. All entities can be extended without schema modifications, localized for international deployments, and linked through flexible polymorphic relationships.
The schema addresses complex data management scenarios including fleet asset hierarchies across organizational levels, multi-tenant SaaS platforms requiring data isolation, compliance-driven operations with detailed audit requirements, and systems needing dynamic data models adaptable through custom fields rather than database migrations.
Data in BDR is synchronized in real-time with source systems. Updates occur immediately as changes happen, with audit trails capturing all modifications for compliance and historical analysis.
ci_base
BDR uses a Single Table Inheritance pattern for all reference data through the ci_base table. This design consolidates system dictionaries, classifications, and user-defined reference items into one unified structure, providing consistency and flexibility across the entire schema.
Architecture:
The ci_base table serves as the foundation for all reference data, using a discriminator field to identify the specific reference type. Each reference type has a corresponding table (like ci_device_type, ci_asset_type) that shares the same id as ci_base, creating a type-safe inheritance relationship. The discriminator isn't set manually. A trigger derives it automatically from the 4-character type code embedded in the entity's UUID, and it fails the insert if the UUID's type code is unrecognized.
Hierarchies (e.g., nested asset types or tags) are handled directly on ci_base through its own parent_id/path columns rather than through separate category tables. A single is_hierarchical flag turns this on per catalog item.
How business entities connect to ci_base:
All business entities in BDR reference ci_base subtypes to define their classification and behavior:
organization and user/member are not typed through ci_base, since organizations and users are core entities in their own right, not classified by a catalog item
GiST index on path for hierarchical queries, unique index on code, index on parent_id
Special notes
Uses ltree for multi-level hierarchies. is_dealer grants the right to create child organizations. version supports optimistic locking
actor
Purpose: Abstraction shared by every ACL principal: users, integrations, and future system actors
Attribute
Details
Key fields
id, actor_type (USER, INTEGRATION, SYSTEM), version
Special notes
All ACL tables (actor_role, acl_role_permission, acl_user_scope) and every deleted_by column key off actor_id, not user_id, so integrations can hold roles and delete records too
user / member
Purpose: User accounts and their organization memberships
Attribute
Details
Key fields
user: id (shared with actor), identity_provider, identity_provider_id, full_name. member: user_id, organization_id, custom_fields_data
Indexing
Unique index on (identity_provider, identity_provider_id). Unique index on (user_id, organization_id) in member
Special notes
A user's org membership is a separate row in member, so one user can belong to multiple organizations. Users authenticate through an external identity provider (Keycloak by default)
integration
Purpose: External systems acting on the platform (e.g. via API keys)
Attribute
Details
Key fields
id (shared with actor), name, credential_ref, is_active
Special notes
credential_ref points at a secure external vault, so no credentials are stored in this table
device / device_identifier
Purpose: Physical tracking devices and their hardware identifiers
GIN trigram index on title for fuzzy search. Unique index on (type, value) for global identifiers, or (type, value, namespace) when namespaced
Special notes
A device can carry multiple identifiers (IMEI, MAC, serial number, etc.) instead of a single hardware ID column. Custom fields live directly in custom_fields_data on the device row
asset
Purpose: Physical or virtual assets
Attribute
Details
Key fields
id, organization_id, asset_type_id, title, custom_fields_data, version
Indexing
Indexes on organization_id and asset_type_id. GIN trigram index on title
Special notes
Custom fields are stored directly on the row, not through a separate customizable-entity table
inventory / device_inventory_relation
Purpose: Inventory and warehouse records, and device assignment to inventory
Schedule data itself (recurrence rules, time windows) is stored in custom_fields_data
asset_group
Purpose: Asset grouping with historical tracking
Attribute
Details
Key fields
id, organization_id, group_type_id, title_en, color
Relationships
FROM bdr.asset_group AS ag JOIN bdr.asset_group_item AS agi ON agi.group_id = ag.id JOIN bdr.asset AS a ON a.id = agi.asset_id WHERE agi.detached_at IS NULL
Special notes
Time-based membership via asset_group_item, query current members with WHERE detached_at IS NULL. Allowed member types per group type are constrained via asset_group_type_to_asset_type_relation
ci_custom_field_definition
Purpose: Custom field definitions and metadata, modeled as a catalog item
Attribute
Details
Key fields
id (shared with ci_base), owner_catalog_item_id, target_entity_type_id, field_type, is_required, params
Content
12 field types: STRING, TEXT, NUMBER, BOOLEAN, DATE, DATETIME, GEOJSON, SCHEDULE, OPTIONS, DEVICE, REFERENCE, CATALOG, TAG
Special notes
Values are stored both as the source of truth (custom_fields_data JSONB on the owning entity) and, per type, in a dedicated custom_field_value_* cache table for filtering/sorting. OPTIONS is a wrapper around CATALOG, and each OPTIONS field gets its own hidden user catalog under the hood
Action bitmask (READ=1, CREATE=2, UPDATE=4, DELETE=8), target-specific or entity-type-wide permissions
Relationships
FROM bdr.actor_role AS ar JOIN bdr.acl_role_permission AS rp ON rp.role_id = ar.role_id WHERE ar.actor_id = $actor_id
Special notes
Effective permissions = role permissions ∩ acl_user_scope. An actor's acl_user_scope is a whitelist filter: empty means unrestricted role access, filled means access is narrowed to the listed objects
Physically partitioned by occurred_at (monthly range partitions, auto-created). event_category is auth (LOGIN, LOGOUT, FAILED_LOGIN, PASSWORD_RESET, SESSION_EXPIRED) or domain (CREATED, UPDATED, DELETED, RESTORED, ROLE_ASSIGNED, ROLE_REVOKED, PERMISSION_GRANTED, PERMISSION_REVOKED, LINKED, UNLINKED, ATTACHED, DETACHED). source_type and trace_id support distributed tracing, and the table stores field-level change deltas in event_data JSONB
Data relationships
BDR implements sophisticated relationship patterns for flexible data modeling:
Hierarchical structures
Organizations use ltree paths for efficient tree queries
Reference items (ci_base) support optional hierarchies through their own parent_id/path, gated by is_hierarchical
Automatic path maintenance via database triggers
Inheritance patterns
ID inheritance: ci_base → reference type tables (ci_device_type, ci_asset_type, etc.), and actor → user and integration
Custom fields are attached per-entity via a custom_fields_data JSONB column directly on each business table (device, asset, geo_object, schedule), rather than through a shared base entity table
Type discrimination via the discriminator field on ci_base, derived automatically from the entity's UUID
Optimistic locking
Business entities and ci_base rows carry a version integer. Updates use SET version = version + 1 WHERE id = $id AND version = $expected_version. Zero affected rows signals a version conflict, letting clients detect and resolve concurrent edits without database-level locks. audit_event and other append-only or bulk-operated tables don't use this pattern.
Polymorphic relationships
Certain tables use polymorphic references without foreign key constraints for maximum flexibility:
acl_role_permission.target_entity_id and acl_user_scope.target_entity_id → any business entity
audit_event.aggregate_id → any business entity, paired with aggregate_type
custom_field_value_entity.ref_entity_id → any business entity
These relationships are validated at the application level.
Additional information
Data validation
BDR enforces data integrity through multiple mechanisms:
Database constraints
UNIQUE constraints with soft delete support (partial indexes WHERE deleted_at IS NULL)
CHECK constraints (e.g., device_relation ensures first_id ≠ second_id, and ci_base.code must start with a letter)
NOT NULL constraints on required fields
DEFAULT values for timestamps, booleans, and JSONB columns
Application-level validation
Entity type validation for polymorphic references
Catalog validation for custom field references
Custom field type validation
Optimistic-locking version checks on update
Query optimization
Tables are organized with specific indexing strategies:
Standard indexes:
All foreign keys have dedicated indexes
Time-based indexes on created_at, updated_at, deleted_at
Composite indexes for frequently joined columns
Specialized indexes:
GiST indexes on ltree paths for hierarchical queries
Partial unique indexes supporting soft delete
GIN trigram (pg_trgm) indexes for fuzzy search on title/title_en and translated text
Custom field value indexes for filtering and sorting
Audit event indexes on time + entity for efficient lookups
Performance considerations:
Connection pooling recommended (PgBouncer)
Regular VACUUM maintenance for large tables
audit_event is physically partitioned by month, so older partitions can be detached or archived independently
Materialized views for complex access control calculations
-- Get all device types for an organization (system + custom)
SELECT cb.id, cb.code, cb.title_en, cb.is_system
FROM bdr.ci_base cb
JOIN bdr.ci_device_type dt ON dt.id = cb.id
WHERE cb.discriminator = 'device_type'
AND (cb.is_system = true OR cb.organization_id = $org_id)
AND cb.deleted_at IS NULL;
-- Get device models with their vendor
SELECT
cb.code as model_code,
cb.title_en as model_name,
vendor_cb.title_en as vendor_name
FROM bdr.ci_base cb
JOIN bdr.ci_device_model dm ON dm.id = cb.id
JOIN bdr.ci_device_vendor v ON v.id = dm.vendor_id
JOIN bdr.ci_base vendor_cb ON vendor_cb.id = v.id
WHERE cb.discriminator = 'device_model'
AND cb.deleted_at IS NULL;
-- Get hierarchical tag structure
SELECT cb.id, cb.code, cb.title_en, cb.path, cb.parent_id
FROM bdr.ci_base cb
JOIN bdr.ci_tag t ON t.id = cb.id
WHERE cb.discriminator = 'tag'
AND cb.deleted_at IS NULL
ORDER BY cb.path;