Composable query scopes for Attached.Originals.Original.
Each scope takes a query (or the Original schema) and returns a refined query.
Designed for the :query hook in Attached.Originals.list/1 and Attached.Originals.count/1:
Attached.Originals.list(
query: &Attached.Originals.Scopes.orphans(&1, "users", "avatar_attached_original_id")
)
Summary
Functions
Restricts a query to originals belonging to a specific (owner_table, owner_field) group.
Restricts a query to orphaned originals within a single (owner_table, owner_field) group.
Restricts a query to originals that are safe to purge: orphaned within the
given (owner_table, owner_field) group and past the configured grace
period.
Functions
Restricts a query to originals belonging to a specific (owner_table, owner_field) group.
Restricts a query to orphaned originals within a single (owner_table, owner_field) group.
An original is orphaned when no row in owner_table references it via the
owner_field column. The group is required because SQL identifiers
(table/column names) can't be bound per row — iterate
Attached.Originals.list_owner_groups/0 to cover every group.
Restricts a query to originals that are safe to purge: orphaned within the
given (owner_table, owner_field) group and past the configured grace
period.
The grace period (config :attached, :orphan_grace_period, in seconds,
default 48 hours, 0 disables it) protects originals created ahead of
their attachment — e.g. a direct upload whose form hasn't been submitted
yet — from being swept while still in flight.
This is the scope behind Attached.Originals.PurgeOrphansWorker and
Attached.Originals.purge_by_owner_group/2. Use orphans/3 directly for
reporting, where fresh orphans should be visible.