iteration

Reads and writes the iterations table and its iteration_tasks join table, which places tasks in phases.

const SELECT_COLUMNS

source

pub(in crate::store::repo) const SELECT_COLUMNS: &str = "\
  id, project_id, title, status, description, \
  metadata, completed_at, created_at, updated_at";

The columns of iterations, in the order that Model::try_from(Row) reads them.

struct IterationTaskRow

source

pub struct IterationTaskRow

A task’s summary info within an iteration context.

Field Type Description
blocked_by Vec<String> Short ids of tasks that block this task (empty when no blockers exist).
id String Full task id.
id_short String Truncated task id suitable for display.
is_blocking bool True when this task blocks at least one other task.
phase u32 Phase number within the iteration.
priority Option<u8> Task priority (lower numbers are higher priority).
status String Task status string as stored in the database.
title String Task title.

struct StatusCounts

source

pub struct StatusCounts

Status counts for tasks in an iteration.

Field Type Description
cancelled i64 Number of tasks in the cancelled state.
done i64 Number of tasks in the done state.
in_progress i64 Number of tasks in the in-progress state.
open i64 Number of tasks in the open state.
total i64 Total number of tasks across all states.

Implements Clone, Default.

struct BlockingInfo

source

struct BlockingInfo

Batched blocker/blocking lookup for a single task inside an iteration.

Field Type Description
blockers Vec<String> Full ids of the tasks that block this task.
is_blocking bool True when this task blocks at least one other task.

Implements Default.

fn add_task

source

pub async fn add_task(
    conn: &Connection,
    iteration_id: &Id,
    task_id: &Id,
    phase: u32,
) -> Result<(), Error>

Add a task to an iteration at a specific phase.

The insert is INSERT OR IGNORE, so a task already in the iteration keeps its phase.

Parameter Type Description
conn &Connection the database connection
iteration_id &Id the full id of the iteration
task_id &Id the full id of the task
phase u32 the phase number to place the task in
returns Result<(), Error> Ok(()) whether or not a row was inserted; an error when the insert fails.

fn add_task_recorded

source

pub async fn add_task_recorded(
    conn: &Connection,
    transaction_id: &Id,
    iteration_id: &Id,
    task_id: &Id,
    phase: u32,
) -> Result<(), Error>

Add a task to an iteration as part of a transaction, so that undo removes it.

The created event on iteration_tasks is recorded only when the task was not already in the iteration, with the row’s key columns as its before_data. A task that was already there keeps its phase and is left out of the transaction, so undo keeps it.

Parameter Type Description
conn &Connection the database connection
transaction_id &Id the transaction the event belongs to
iteration_id &Id the full id of the iteration
task_id &Id the full id of the task
phase u32 the phase number to place the task in
returns Result<(), Error> Ok(()) whether or not a row was inserted; an error when a query fails.

fn insert_task

source

async fn insert_task(
    conn: &Connection,
    iteration_id: &Id,
    task_id: &Id,
    phase: u32,
) -> Result<bool, Error>

Inserts the task into the iteration with INSERT OR IGNORE, and returns whether a row was inserted.

Parameter Type Description
conn &Connection
iteration_id &Id
task_id &Id
phase u32
returns Result<bool, Error>

fn all

source

pub async fn all(conn: &Connection, project_id: &Id, filter: &Filter) -> Result<Vec<Model>, Error>

Return iterations for a project, applying the given filter.

Parameter Type Description
conn &Connection the database connection
project_id &Id the full id of the project
filter &Filter the status, tag and availability filters; without all, completed and cancelled iterations are left out
returns Result<Vec<Model>, Error> The iterations, newest first.

fn create

source

pub async fn create(conn: &Connection, project_id: &Id, new: &New) -> Result<Model, Error>

Create a new iteration in the given project.

The iteration gets a fresh id, the default status and an empty {} metadata object when none is given.

Parameter Type Description
conn &Connection the database connection
project_id &Id the full id of the project
new &New the title, description and optional metadata
returns Result<Model, Error> The iteration as read back after the insert, or an error when the insert fails or the row cannot be read back.

fn find_by_id

source

pub async fn find_by_id(conn: &Connection, id: impl Into<Id>) -> Result<Option<Model>, Error>

Find an iteration by its Id.

Parameter Type Description
conn &Connection the database connection
id impl Into<Id> the full id of the iteration
returns Result<Option<Model>, Error> The iteration, or None when no iteration has that id.

fn find_required_by_id

source

pub async fn find_required_by_id(conn: &Connection, id: impl Into<Id>) -> Result<Model, Error>

Find an iteration by its Id, returning Error::NotFound when no row matches.

Parameter Type Description
conn &Connection the database connection
id impl Into<Id> the full id of the iteration
returns Result<Model, Error> The iteration, or a database error. The Error::NotFound names the iteration’s short id.

fn max_phase

source

pub async fn max_phase(conn: &Connection, iteration_id: &Id) -> Result<Option<u32>, Error>

Get the maximum phase number for an iteration, or None if empty.

Parameter Type Description
conn &Connection the database connection
iteration_id &Id the full id of the iteration
returns Result<Option<u32>, Error> The highest phase among the iteration’s tasks, or a database error.

fn max_phases_batch

source

pub async fn max_phases_batch(
    conn: &Connection,
    iteration_ids: &[Id],
) -> Result<HashMap<Id, Option<u32>>, Error>

Get the maximum phase number for each iteration in a single query.

Parameter Type Description
conn &Connection the database connection
iteration_ids &[Id] the full ids of the iterations; an empty slice runs no query
returns Result<HashMap<Id, Option<u32>>, Error> Iterations with no tasks will not appear in the returned map.

fn task_status_counts_batch

source

pub async fn task_status_counts_batch(
    conn: &Connection,
    iteration_ids: &[Id],
) -> Result<HashMap<Id, StatusCounts>, Error>

Return task counts grouped by status for each iteration in a single query.

Parameter Type Description
conn &Connection the database connection
iteration_ids &[Id] the full ids of the iterations; an empty slice runs no query
returns Result<HashMap<Id, StatusCounts>, Error> Iterations with no tasks will not appear in the returned map.

fn prefix_length_for_id

source

pub async fn prefix_length_for_id(
    conn: &Connection,
    project_id: &Id,
    id: &str,
) -> Result<usize, Error>

Return the minimum unique prefix length for a single iteration in the project.

Narrows the disambiguation pool to iterations whose ID shares at least the first character with id — an ID that differs at character 0 can never force the prefix longer than 1, so omitting it preserves the same result as prefix_lengths_for_project while avoiding a full-table scan.

Uses two-tier resolution: if the target is non-terminal it is resolved against the active pool only; otherwise it is resolved against the full pool.

Parameter Type Description
conn &Connection the database connection
project_id &Id the full id of the project
id &str the full id of the iteration, as text
returns Result<usize, Error> The length; 1 when id is empty.

fn prefix_lengths_for_project

source

pub async fn prefix_lengths_for_project(
    conn: &Connection,
    project_id: &Id,
    iteration_ids: &[&str],
) -> Result<Vec<usize>, Error>

Return per-ID prefix lengths using two-tier resolution: active iterations (non-terminal status) are resolved against the active pool, while archived iterations (completed/cancelled) are resolved against the full pool.

Parameter Type Description
conn &Connection the database connection
project_id &Id the full id of the project
iteration_ids &[&str] the full ids to measure, as text
returns Result<Vec<usize>, Error> The returned Vec<usize> is aligned to iteration_ids. An id that is not in the project gets 2.

fn remove_task_recorded

source

pub async fn remove_task_recorded(
    conn: &Connection,
    transaction_id: &Id,
    iteration_id: &Id,
    task_id: &Id,
) -> Result<bool, Error>

Remove a task from an iteration as part of a transaction, so that undo puts it back in the same phase.

The deleted event on iteration_tasks is recorded only when the task was in the iteration, with the whole row (its phase and created_at too) as before_data.

Parameter Type Description
conn &Connection the database connection
transaction_id &Id the transaction the event belongs to
iteration_id &Id the full id of the iteration
task_id &Id the full id of the task
returns Result<bool, Error> true when a row was removed, false when the task was not in the iteration, or an error when a query fails.

fn delete_task_row

source

async fn delete_task_row(conn: &Connection, iteration_id: &Id, task_id: &Id) -> Result<bool, Error>

Deletes the iteration_tasks row, and returns whether there was one.

Parameter Type Description
conn &Connection
iteration_id &Id
task_id &Id
returns Result<bool, Error>

fn task_status_counts

source

pub async fn task_status_counts(conn: &Connection, iteration_id: &Id) -> Result<StatusCounts, Error>

Return task counts grouped by status for an iteration.

Parameter Type Description
conn &Connection the database connection
iteration_id &Id the full id of the iteration
returns Result<StatusCounts, Error> The counts and their total; all zero when the iteration has no tasks.

fn tasks_with_phase

source

pub async fn tasks_with_phase(
    conn: &Connection,
    iteration_id: &Id,
) -> Result<Vec<IterationTaskRow>, Error>

Return all tasks for an iteration with phase, priority, and blocking data.

Runs two queries: one for the base task rows (joined to the tasks table for priority) and a batched query over relationships to resolve blockers and blocking flags for every task in a single pass.

Parameter Type Description
conn &Connection the database connection
iteration_id &Id the full id of the iteration
returns Result<Vec<IterationTaskRow>, Error> The tasks ordered by phase, then title; blockers are given by short id.

fn resolve_blocking_batch

source

async fn resolve_blocking_batch(
    conn: &Connection,
    iteration_id: &Id,
) -> Result<HashMap<String, BlockingInfo>, Error>

Return (blockers, is_blocking) info keyed by full task id for every task that participates in a blocks / blocked-by relationship touching the iteration. Tasks with no entries in the map have no blocking data.

Parameter Type Description
conn &Connection the database connection
iteration_id &Id the full id of the iteration
returns Result<HashMap<String, BlockingInfo>, Error> The map, or an error when the query fails.

fn collect_ids

source

async fn collect_ids(conn: &Connection, sql: &str, project_id: &Id) -> Result<Vec<String>, Error>

Run a query that selects ids for one project, and collect the first column.

Parameter Type Description
conn &Connection the database connection
sql &str a query with one ?1 parameter, the project id, whose first column is an id
project_id &Id the full id of the project
returns Result<Vec<String>, Error> The ids, as text, in the order the query returns them.

fn update

source

pub async fn update(conn: &Connection, id: &Id, patch: &Patch) -> Result<Model, Error>

Update an existing iteration with the given patch.

updated_at is always set to now. A status in the patch, even the current one, sets completed_at to now for a terminal status and clears it otherwise.

Parameter Type Description
conn &Connection the database connection
id &Id the full id of the iteration
patch &Patch the fields to change
returns Result<Model, Error> The updated iteration, or Error::NotFound when no iteration has that id.

fn task_phase

source

pub async fn task_phase(conn: &Connection, task_id: &Id) -> Result<Option<u32>, Error>

Return the current phase of a task within its iteration, if any.

Parameter Type Description
conn &Connection the database connection
task_id &Id the full id of the task
returns Result<Option<u32>, Error> The phase from one of the task’s iteration_tasks rows, if there are several; None when it is in no iteration.

fn update_task_phase

source

pub async fn update_task_phase(conn: &Connection, task_id: &Id, phase: u32) -> Result<(), Error>

Update the phase of a task within its iteration.

Every iteration_tasks row for the task is changed.

Parameter Type Description
conn &Connection the database connection
task_id &Id the full id of the task
phase u32 the new phase number
returns Result<(), Error> Ok(()) even when the task is in no iteration; an error when the update fails.

fn update_task_phase_recorded

source

pub async fn update_task_phase_recorded(
    conn: &Connection,
    transaction_id: &Id,
    task_id: &Id,
    phase: u32,
) -> Result<(), Error>

Update the phase of a task in every iteration it belongs to, as part of a transaction, so that undo puts each old phase back.

For each iteration_tasks row whose phase changes, a modified event is recorded with the row’s key columns and its old phase as before_data.

Parameter Type Description
conn &Connection the database connection
transaction_id &Id the transaction the events belong to
task_id &Id the full id of the task
phase u32 the new phase number
returns Result<(), Error> Ok(()) even when the task is in no iteration; an error when a query fails.