project

Reads and writes the projects and project_workspaces tables, and archives and deletes whole projects.

struct DeleteSummary

source

pub struct DeleteSummary

Per-table counts of rows removed by a delete call.

Returned so that callers (e.g. the CLI) can render cascade counts in a confirmation prompt.

Field Type Description
artifacts usize Number of owned artifacts removed.
iterations usize Number of owned iterations removed.
notes usize Number of attached notes removed (across all entities).
relationships usize Number of relationships removed (across all entities).
tags usize Number of entity_tags attachments removed (across all entities).
tasks usize Number of owned tasks removed.

Implements Clone, Copy, Debug, Default, Eq, PartialEq.

fn all

source

pub async fn all(conn: &Connection, include_archived: bool) -> Result<Vec<Project>, Error>

Return projects ordered by creation time (newest first).

Parameter Type Description
conn &Connection the database connection
include_archived bool When include_archived is false, only active (non-archived) projects are returned. Pass true to include archived projects in the result set.
returns Result<Vec<Project>, Error> The projects, or an error when the query fails.

fn archive

source

pub async fn archive(conn: &Connection, id: &Id) -> Result<(), Error>

Soft-archive a project by setting archived_at to now and deleting all associated workspace rows in a single operation.

Parameter Type Description
conn &Connection the database connection
id &Id the full id of the project
returns Result<(), Error> Ok(()) once both statements run, even when no project has that id; an error when a statement fails.

fn attach_workspace

source

pub async fn attach_workspace(
    conn: &Connection,
    project_id: &Id,
    path: impl Into<PathBuf>,
) -> Result<ProjectWorkspace, Error>

Attach a workspace path to a project, creating a new ProjectWorkspace.

Parameter Type Description
conn &Connection the database connection
project_id &Id the full id of the project
path impl Into<PathBuf> the workspace directory to attach
returns Result<ProjectWorkspace, Error> The new workspace, or an error when the insert fails, for example when the path is already attached to this project.

fn count_owned

source

pub async fn count_owned(conn: &Connection, table: Table, project_id: &Id) -> Result<usize, Error>

Count rows in table owned by the given project (matching project_id).

Parameter Type Description
conn &Connection the database connection
table Table the entity table to count, which must have a project_id column
project_id &Id the full id of the project
returns Result<usize, Error> The number of matching rows.

fn create

source

pub async fn create(conn: &Connection, root: impl Into<PathBuf>) -> Result<Project, Error>

Create a new project for the given root path.

If a .gest/project.yaml already exists at the root or any ancestor directory, the project’s stable id is read from that file (so collaborators share the same id) and a row is inserted with the local checkout’s path. Otherwise a fresh project id is generated and .gest/project.yaml is written when a .gest directory exists.

When a .gest directory is found, its project.yaml is (re)written with the new row’s id and timestamps.

Parameter Type Description
conn &Connection the database connection
root impl Into<PathBuf> the project’s root directory
returns Result<Project, Error> The project as read back after the insert, or an error when project.yaml cannot be read, parsed or written, or the insert fails.

fn find_or_create_from_synced_project

source

pub async fn find_or_create_from_synced_project(
    conn: &Connection,
    root: impl Into<PathBuf>,
    gest_dir: &Path,
) -> Result<Option<Project>, Error>

Find or create the project row described by a synced .gest/project.yaml.

This is used when a project-local SQLite cache is missing or empty but the repository still has its committed sync mirror. Returning None means the .gest directory is not a synced project root yet.

Parameter Type Description
conn &Connection the database connection
root impl Into<PathBuf> the local checkout root, used when a new row is created
gest_dir &Path the .gest directory that may hold project.yaml
returns Result<Option<Project>, Error> The existing or newly created project; None when project.yaml is missing or carries a deleted_at tombstone.

struct ProjectFile

source

struct ProjectFile

On-disk shape of .gest/project.yaml. Only fields that should travel with the repository are persisted; the local checkout root lives in SQLite.

Field Type Description
id Id The project’s stable id, shared by every checkout of the repository.
created_at chrono::DateTime<chrono::Utc> When the project was first registered.
updated_at chrono::DateTime<chrono::Utc> When the project record was last modified.
deleted_at Option<chrono::DateTime<chrono::Utc>> When the project was deleted; set only on a tombstone, and omitted from the file otherwise.

Implements Debug, Deserialize<'de>, Serialize.

fn delete

source

pub async fn delete(
    conn: &Connection,
    id: &Id,
    gest_dir: Option<&Path>,
    deleted_at: DateTime<Utc>,
) -> Result<DeleteSummary, Error>

Hard-delete a project and every entity it owns, inside a single logical operation.

This is a non-undoable, cascade delete that:

  1. Enumerates all tasks, iterations, and artifacts owned by the project.
  2. Calls entity::delete::delete_with_cascade for each so child rows (notes, entity_tags, relationships, iteration_tasks) are cleaned up.
  3. Writes tombstone files for every owned entity and the project itself.
  4. Deletes transactions rows referencing the project.
  5. Deletes project_workspaces rows referencing the project.
  6. Deletes the projects row itself.

No transaction record is opened – project delete is explicitly non-undoable.

Parameter Type Description
conn &Connection the database connection
id &Id the full id of the project
gest_dir Option<&Path> the project’s .gest directory, where tombstones are written; None when there is none
deleted_at DateTime<Utc> the deletion time written into each tombstone
returns Result<DeleteSummary, Error> The per-table counts of what was removed, or the first error; the steps before it are not rolled back.

fn detach_workspace

source

pub async fn detach_workspace(conn: &Connection, path: &Path) -> Result<bool, Error>

Detach the workspace for the given path, removing it from its project.

Parameter Type Description
conn &Connection the database connection
path &Path the workspace path, matched exactly
returns Result<bool, Error> Returns true if a workspace was deleted, false if none matched.

fn find_by_id

source

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

Find a project by its Id.

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

fn find_by_path

source

pub async fn find_by_path(conn: &Connection, path: &Path) -> Result<Option<Project>, Error>

Find a project by path.

Parameter Type Description
conn &Connection the database connection
path &Path the directory to look up, matched exactly
returns Result<Option<Project>, Error> Matches against both the project’s root path and any associated workspace path. Returns the first matching project. It is None when no project matches.

struct EntityCounts

source

pub struct EntityCounts

Counts of entities owned by a project, used for confirmation prompts.

Field Type Description
artifacts usize Number of artifacts owned by the project.
iterations usize Number of iterations owned by the project.
tasks usize Number of tasks owned by the project.
workspaces usize Number of workspace paths attached to the project.

Implements Clone, Copy, Debug, Default, Eq, PartialEq.

fn entity_counts

source

pub async fn entity_counts(conn: &Connection, id: &Id) -> Result<EntityCounts, Error>

Return counts of workspaces and owned entities for a project.

Used by the archive confirmation prompt to show what will be affected.

Parameter Type Description
conn &Connection the database connection
id &Id the full id of the project
returns Result<EntityCounts, Error> One count each for artifacts, iterations, tasks and workspaces.

fn unarchive

source

pub async fn unarchive(conn: &Connection, id: &Id) -> Result<(), Error>

Clear the archived_at timestamp on a project, restoring it to active.

Workspaces removed by archive are not restored.

Parameter Type Description
conn &Connection the database connection
id &Id the full id of the project
returns Result<(), Error> Ok(()) once the update runs, even when no project has that id; an error when it fails.

fn collect_entity_ids

source

async fn collect_entity_ids(
    conn: &Connection,
    table: Table,
    project_id: &Id,
) -> Result<Vec<Id>, Error>

Collect all entity ids from a table that belong to the given project.

Parameter Type Description
conn &Connection the database connection
table Table the entity table to read
project_id &Id the full id of the project
returns Result<Vec<Id>, Error> The ids of the matching rows, or an error when an id cannot be parsed.

fn count_project_workspaces

source

async fn count_project_workspaces(conn: &Connection, project_id: &Id) -> Result<usize, Error>

Count project_workspaces rows belonging to the given project.

project_workspaces is not an entity table in Table, so its count uses a hand-written query rather than the shared count_owned helper.

Parameter Type Description
conn &Connection the database connection
project_id &Id the full id of the project
returns Result<usize, Error> The number of workspaces attached to the project.

fn find_gest_dir

source

fn find_gest_dir(start: &Path) -> Option<PathBuf>

Walk from start upward through ancestor directories looking for a .gest directory. Returns the path to the .gest directory if found.

Parameter Type Description
start &Path the directory to start from; it is checked first
returns Option<PathBuf> The nearest match; None when there is none.

fn invalidate_sync_digest

source

async fn invalidate_sync_digest(
    conn: &Connection,
    project_id: &Id,
    relative: &str,
) -> Result<(), Error>

Drop the digest-cache entry for a sync file so follow-up exports don’t skip the tombstoned file.

Parameter Type Description
conn &Connection the database connection
project_id &Id the full id of the project
relative &str the file’s path relative to the .gest directory
returns Result<(), Error> Ok(()) whether or not a digest row existed; an error when the delete fails.