Skip to main content

replace_for_exercise_task

Function replace_for_exercise_task 

Source
pub async fn replace_for_exercise_task(
    conn: &mut PgConnection,
    exercise_task_id: Uuid,
    spec_kind: SpecKind,
    file_upload_ids: &[Uuid],
) -> ModelResult<()>
Expand description

Replaces what one of a task’s specs declares with file_upload_ids.

Scoped to a single kind: storing a derived spec must not disturb what the private spec declares, and vice versa. Rewriting in full is what makes a dropped file reclaimable — the rows for files no longer named are soft-deleted, and once no history version names them either the upload becomes reapable. Re-declaring a file that is already recorded leaves its row alone, so a save that changes nothing does not churn the table.

Fails with PreconditionFailed on an id the host has no live upload for, or one the reaper has already reclaimed, naming it: the caller is relaying a list an exercise service sent, and a bad id is that service’s bug, not a reason to surface a foreign key violation from a page save.