Adventure Labs Logo
Scout Docs

Documents

Compliance documents owned by exactly one of a user, herd, device, or product

Column NameData TypeConstraints
idbigintNOT NULL
uritextNOT NULL
size_bytesbigint
template_idbigintFK -> document_templates
valid_fromtimestamp with time zone
valid_totimestamp with time zone
user_iduuidFK -> users
herd_idbigintFK -> herds
device_idbigintFK -> devices
product_idbigintFK -> products
created_byuuidFK -> users
created_attimestamp with time zoneDEFAULT now() NOT NULL
updated_byuuidFK -> users
updated_attimestamp with time zoneDEFAULT now() NOT NULL
is_approvedbooleanDEFAULT false NOT NULL
approved_byuuidFK -> users
approved_attimestamp with time zone

Exactly one of user_id, herd_id, device_id, or product_id is set (documents_exactly_one_owner).

Security Policies (RLS)

RLS enabled. Scope: Access resolved from the owner via document_access.

OwnerSELECTINSERT / UPDATE / DELETE
herdherd_documents.readherd_documents.write
devicedevice_documents.read (device's herd)device_documents.write
producthas_view_role_any_herdsuperadmin only
userowner, or user_documents.read in a shared herdowner, or user_documents.write in a shared herd

Platform superadmin: FOR ALL bypass where defined.

Approval

Only user documents go through review. is_approved / approved_by / approved_at on a user document may be changed only by a holder of document_approve.binary in a shared herd (documents_approval_guard). Documents owned by a herd, device, product, or operating context are approved on insert by the same trigger, and later approval edits need only the owner's write ability.

Approved user documents cannot be deleted; other documents can be deleted by anyone with write access. Status-only reads of user documents are available through User_document_statuses.

On this page