org.documents
Polymorphic file attachments. Delete-only (no is_active, no updated_at); replacing a file is delete + add.
Columns
| Column | Type | Notes |
|---|---|---|
id | UUID PK | |
org_id | UUID FK | → platform.organizations(id). |
entity_type | org.entity_document_kind | NOT NULL. ENUM (sales_order, purchase_order, work_order). Values added later via ALTER TYPE ADD VALUE. |
entity_id | UUID | NOT NULL. Id of the row in the corresponding entity table. No DB-level FK — application-enforced cleanup. |
name | VARCHAR(255) | NOT NULL. Display name shown in the UI. |
gcs_path | TEXT | NOT NULL. Object path inside the bucket (e.g., orgs/{orgId}/sales-orders/{soId}/{uuid}-{filename}). Signed URLs are generated per request by the Documents L2 component — not stored. |
mime_type | VARCHAR(100) | Content type at upload time (application/pdf, image/png, etc.). |
size_bytes | BIGINT | File size in bytes. |
created_at | TIMESTAMPTZ | NOT NULL. Default NOW(). |
Index: (entity_type, entity_id) — supports "all documents for entity X" queries.
Cross-references
- Linked from sales orders (
entity_type = 'sales_order'). - Linked from purchase orders (
entity_type = 'purchase_order'). - Linked from work orders (
entity_type = 'work_order').