Skip to content
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

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.

The interactive diagram of the BDR data schema is available on dbdiagram.io: https://dbdiagram.io/d/Navixy-Repo-data-schema-68ad788c1e7a611967a0930e

Find the BDR schema details below.

Update frequency

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

  • device → references ci_device_type, optionally ci_device_model (which itself references ci_device_vendor), and ci_device_status

  • asset → references ci_asset_type

  • asset_group → references ci_asset_group_type, with allowed member types constrained via asset_group_type_to_asset_type_relation

  • geo_object → references ci_geo_object_type

  • schedule → references ci_schedule_type

  • inventory has no catalog-item type of its own

Reference type categories:

Category
Tables
Purpose

System configuration

ci_module, ci_country, ci_role

Define system modules, geographic references, and user roles

Entity type definitions

ci_entity_type, ci_device_type, ci_asset_type, ci_geo_object_type, ci_schedule_type, ci_asset_group_type

Classify all business entities by type

Device catalog

ci_device_vendor, ci_device_model, ci_device_status

Model devices by manufacturer, model, and current status

Access control

ci_permission_scope

Define what permissions can be granted (connected to ci_module and ci_entity_type)

Relationships

ci_device_relation_type

Define types of relationships between devices (master-slave, backup, etc.)

Categorization

ci_tag, ci_catalog_category, ci_user_catalog_item

Enable flexible tagging and user-defined catalogs

Catalog / custom fields

ci_catalog, ci_custom_field_definition

Catalog-of-catalogs and custom field metadata, both modeled as catalog items themselves

Example query patterns

Key tables by category

The tables in BDR are organized into functional categories. The descriptions below summarize the most important tables by their business purpose.

organization

Purpose: Hierarchical organization management

Attribute
Details

Key fields

id, parent_id, path, code, title_en, is_active, is_dealer, version, deleted_at

Indexing

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

Attribute
Details

Key fields

device: id, organization_id, device_type_id, model_id, status_id, title, custom_fields_data, version. device_identifier: device_id, type, value, namespace

Indexing

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

Attribute
Details

Key fields

inventory: id, organization_id, title, code. device_inventory_relation: device_id, inventory_id, assigned_at, deleted_at

Indexing

Unique index on (organization_id, code). A partial unique index ensures a device has at most one active inventory assignment

Special notes

Assignment is soft-deletable, so device-inventory history is preserved

geo_object

Purpose: Geofences, points of interest, and routes

Attribute
Details

Key fields

id, organization_id, geo_object_type_id, title, custom_fields_data

Special notes

Geometry (formerly a dedicated geojson column) is now stored as a custom field inside custom_fields_data

schedule

Purpose: Reusable schedules referenced by other entities

Attribute
Details

Key fields

id, organization_id, schedule_type_id, title, custom_fields_data

Special notes

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

acl_role_permission

Purpose: Role-based permission management

Attribute
Details

Key fields

id, role_id, permission_scope_id, target_entity_id, actions

Content

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

audit_event

Purpose: Unified audit log for all system changes

Attribute
Details

Key fields

id, organization_id, event_category, actor_id, source_type, trace_id, aggregate_type, aggregate_id, event_type, event_data, occurred_at

Indexing

Indexes on (actor_id, occurred_at), (aggregate_type, aggregate_id, occurred_at), (event_category, occurred_at), (organization_id, occurred_at)

Special notes

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

Last updated

Was this helpful?