Tearleads

blobs API Postgres table

Committed encrypted blob payloads.

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

Description

A blob row points to encrypted bytes after a staged upload has been promoted by an authorized attachment mutation. Access to bytes is checked through current attachment bindings and document/container access before the object is returned.

Columns

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

    Stable blob id.

  • storage_keytext
    • not null

    Storage key for the encrypted bytes.

  • sha256text
    • not null

    SHA-256 digest of the encrypted object.

  • byte_lengthinteger
    • not null

    Byte length of the encrypted object.

  • created_attimestamp
    • not null
    • default now()

    Server-side promotion timestamp.

  • dereferenced_attimestamp
    • nullable

    Set when detach, replacement, or purge leaves this blob without an active attachment binding. The bytes are retained during a GC grace period; a later sweep locks the blob and re-checks active reachability before pruning live state. A bind that re-references it clears this back to null. Null while live.

  • reclaim_attempted_attimestamp
    • nullable

    Most recent failed live-state reclaim attempt. This places corrupt work in a retry class with reserved batch capacity without changing the lifecycle-defining dereferencedAt. Cleared when revived.

Indexes

  • blobs_storage_key_idx(storage_key)
    • unique

    One blob row per object-store key: a blob is 1:1 with its bytes (sharing across documents goes through attachment_bindings, not duplicate rows). This makes a second concurrent bind that aliases an already-consumed stage's storage key conflict and fail closed instead of creating two blob rows over one object (which would break storage-key GC reachability).

  • blobs_dereferenced_at_idx(dereferenced_at)
    • partial: where "dereferenced_at" is not null
  • blobs_reclaim_attempted_at_idx(reclaim_attempted_at, dereferenced_at, id)
    • partial: where "reclaim_attempted_at" is not null and "dereferenced_at" is not null