Tearleads

containers API Postgres table

Materialized container tree structure.

Declared in packages/api-shared/src/schema/containers.ts

Description

This table stores only the mutable structural shape needed for container listing and parent-child checks. Authorization, grants, metadata-document pointers, and KEK target state are verified from signed access manifests and their projection tables.

Indexes:

  • organizationId where parentId and systemSlot are null is unique so an organization has one personal root container.
  • organizationId, systemSlot where systemSlot is not null keeps each system slot unique per organization.
  • (parentId, discoveryOrder, id) supports parent-container sync lanes, direct child lookups, and move validation.
  • (organizationId, depth) keeps depth indexed for tree traversal and depth-bounded maintenance without indexing updatedAt, keeping touchContainers HOT-eligible.

Columns

  • iduuid
    • primary key
    • not null
    • default gen_random_uuid()

    Stable container id.

  • organization_iduuid
    • not null

    Organization boundary for the container. Parent and child containers must stay within the same organization.

  • parent_iduuid
    • nullable

    Parent container id, or null for the personal or metadata root container.

  • system_slottext
    • nullable

    Optional opaque app-owned system slot. System containers are root children except for the independent metadata root, and cannot be removed through the public container delete API.

  • depthinteger
    • not null
    • default 0

    Materialized distance from the root container. Roots are 0.

  • created_attimestamp
    • not null
    • default now()

    Server-side insertion timestamp.

  • discovery_orderbigint
    • not null
    • default 0

    Publication position stamped as a change to the container commits, from a counter shared with documents and both sync tombstone tables. Parent lanes page containers in (discoveryOrder, id) order.

  • updated_attimestamp
    • not null
    • default now()

    Server-side sync timestamp bumped when the container, metadata document, or visible contents change.

Indexes

  • containers_org_root_idx(organization_id)
    • unique
    • partial: where "parent_id" is null and "system_slot" is null
  • containers_org_system_slot_idx(organization_id, system_slot)
    • unique
    • partial: where "system_slot" is not null
  • containers_parent_discovery_idx(parent_id, discovery_order, id)
    • containers_org_depth_idx(organization_id, depth)