v0_4
struct MigrationCounts
struct MigrationCountsCounters for reporting migration results.
| Field | Type | Description |
|---|---|---|
tasks |
usize | Tasks imported. |
artifacts |
usize | Artifacts imported. |
iterations |
usize | Iterations imported. |
notes |
usize | Notes imported from tasks and iterations. |
relationships |
usize | Links imported; a link that could not be imported is not counted. |
skipped |
usize | Files that could not be parsed and were left out. |
Implements Default.
fn run
pub async fn run(context: &AppContext, source: &Path) -> Result<(), Error>Run the v0.4 migration from flat-file .gest/ directory into SQLite.
Creates a project for the current directory when there is none, imports tasks, then artifacts, then iterations, and prints the counts.
| Parameter | Type | Description |
|---|---|---|
context |
&AppContext | the application context: settings, store and current project |
source |
&Path | the legacy .gest/ directory to read |
| returns | Result<(), Error> | Ok(()) once the counts are printed, Error::NotFound when source is not a directory, or the first I/O or store error. |
struct PendingLink
struct PendingLinkA legacy link waiting for every entity to exist, so its target can be looked up by its legacy ID.
| Field | Type | Description |
|---|---|---|
source_type |
EntityType | The kind of the entity that holds the link. |
source_id |
Id | The new ID of the entity that holds the link. |
link |
LegacyLink | The link as the legacy file wrote it. |
struct IdMaps
struct IdMapsLegacy IDs mapped to new IDs, one map for each kind of entity.
| Field | Type | Description |
|---|---|---|
tasks |
HashMap<String, Id> | Legacy task IDs. |
artifacts |
HashMap<String, Id> | Legacy artifact IDs. |
iterations |
HashMap<String, Id> | Legacy iteration IDs. |
fn migrate_all
async fn migrate_all(
conn: &libsql::Connection,
project_id: &Id,
source: &Path,
counts: &mut MigrationCounts,
) -> Result<(), Error>Migrate tasks, artifacts and iterations, then their links.
Links are imported last, so a link can name any entity, including one read after the entity that holds the link.
v0.4 wrote a link on both entities, the second as the inverse; import_link keeps one row for each pair, as
gest task link makes, except between two iterations, where gest iteration link also makes both rows.
| Parameter | Type | Description |
|---|---|---|
conn |
&libsql::Connection | the connection to write to |
project_id |
&Id | the project that owns the imported entities |
source |
&Path | the legacy .gest directory |
counts |
&mut MigrationCounts | the running totals, updated in place |
| returns | Result<(), Error> | Ok(()) once everything is imported, or the first database or I/O error. |
fn migrate_tasks
async fn migrate_tasks(
conn: &libsql::Connection,
project_id: &Id,
source: &Path,
counts: &mut MigrationCounts,
links: &mut Vec<PendingLink>,
) -> Result<HashMap<String, Id>, Error>Migrate tasks and return a mapping of old ID string → new Id.
Reads the .toml files in tasks/ and tasks/resolved/, with their tags, notes and links.
| Parameter | Type | Description |
|---|---|---|
conn |
&libsql::Connection | the database connection |
project_id |
&Id | the project that receives the imported entities |
source |
&Path | the legacy .gest/ directory |
counts |
&mut MigrationCounts | the running totals, updated for each entity, note and skipped file |
links |
&mut Vec<PendingLink> | the links waiting for every entity to exist; this function adds to it |
| returns | Result<HashMap<String, Id>, Error> | Each legacy task ID mapped to its new ID, or the first I/O or store error. A file that does not parse is skipped and counted. |
fn migrate_artifacts
async fn migrate_artifacts(
conn: &libsql::Connection,
project_id: &Id,
source: &Path,
counts: &mut MigrationCounts,
) -> Result<HashMap<String, Id>, Error>Migrate the markdown artifacts in artifacts/ and artifacts/archive/.
Archived artifacts are archived again, and an artifact’s legacy type becomes one more tag.
| Parameter | Type | Description |
|---|---|---|
conn |
&libsql::Connection | the database connection |
project_id |
&Id | the project that receives the imported entities |
source |
&Path | the legacy .gest/ directory |
counts |
&mut MigrationCounts | the running totals, updated for each artifact and skipped file |
| returns | Result<HashMap<String, Id>, Error> | Legacy artifact IDs mapped to their new IDs, or the first I/O or store error. A file that does not parse is skipped and counted. |
fn migrate_iterations
async fn migrate_iterations(
conn: &libsql::Connection,
project_id: &Id,
source: &Path,
counts: &mut MigrationCounts,
task_id_map: &HashMap<String, Id>,
links: &mut Vec<PendingLink>,
) -> Result<HashMap<String, Id>, Error>Migrate the iterations in iterations/ and iterations/resolved/, with their tags, tasks,
notes and links.
Every task joins phase 1; a task ref that was not migrated is logged and left out. An artifact
ref in the task list becomes a relates-to link. Links are collected into links.
| Parameter | Type | Description |
|---|---|---|
conn |
&libsql::Connection | the database connection |
project_id |
&Id | the project that receives the imported entities |
source |
&Path | the legacy .gest/ directory |
counts |
&mut MigrationCounts | the running totals, updated for each entity, note, link and skipped file |
task_id_map |
&HashMap<String, Id> | legacy task IDs mapped to their new IDs, from [migrate_tasks] |
links |
&mut Vec<PendingLink> | the links waiting for every entity to exist; this function adds to it |
| returns | Result<HashMap<String, Id>, Error> | Legacy iteration IDs mapped to their new IDs, or the first I/O or store error. A file that does not parse is skipped and counted. |
fn file_stem
fn file_stem(path: &Path) -> Option<String>The file name of path without its extension, which is the legacy ID of the entity in it.
| Parameter | Type | Description |
|---|---|---|
path |
&Path | |
| returns | Option<String> |
fn import_link
async fn import_link(
conn: &libsql::Connection,
pending: &PendingLink,
maps: &IdMaps,
imported: &mut HashSet<String>,
) -> Result<bool, Error>Import a v0.4 link as a relationship. Links reference entities by path like “tasks/<id>” or “artifacts/<id>”.
An unknown rel, a ref that does not resolve, and a failed insert are each logged and skipped, so one bad link does not stop the migration. A link whose inverse row this import already made is skipped quietly, unless both ends are iterations.
| Parameter | Type | Description |
|---|---|---|
conn |
&libsql::Connection | the database connection |
pending |
&PendingLink | the link and the entity that holds it |
maps |
&IdMaps | legacy IDs mapped to new IDs |
imported |
&mut HashSet<String> | the rows made so far, as [row_key] writes them; updated in place |
| returns | Result<bool, Error> | Ok(true) when the link became a row, Ok(false) when it was skipped. |
fn row_key
fn row_key(
source_type: EntityType,
source_id: &Id,
rel: RelationshipType,
target_type: EntityType,
target_id: &Id,
) -> StringA relationship row as one string, so the rows an import made can be looked up.
| Parameter | Type | Description |
|---|---|---|
source_type |
EntityType | |
source_id |
&Id | |
rel |
RelationshipType | |
target_type |
EntityType | |
target_id |
&Id | |
| returns | String |
fn resolve_link_ref
fn resolve_link_ref(ref_: &str, maps: &IdMaps) -> Option<(EntityType, Id)>Resolve a v0.4 link ref (e.g. “tasks/<id>”, “artifacts/<id>”) to an entity type and new ID.
| Parameter | Type | Description |
|---|---|---|
ref_ |
&str | the legacy ref, a kind folder and an ID |
maps |
&IdMaps | legacy IDs mapped to new IDs |
| returns | Option<(EntityType, Id)> | The entity type and new ID, or None for an unknown kind or an entity that was not migrated. |
fn toml_table_to_json
fn toml_table_to_json(table: &toml::Table) -> Option<Value>Convert a TOML table to a JSON value for metadata storage.
| Parameter | Type | Description |
|---|---|---|
table |
&toml::Table | the legacy metadata table |
| returns | Option<Value> | The JSON object, or None when the table is empty or does not convert. |
fn read_files_with_ext
fn read_files_with_ext(dir: &Path, ext: &str) -> std::io::Result<Vec<PathBuf>>List the files in dir with the extension ext, not looking into subdirectories.
| Parameter | Type | Description |
|---|---|---|
dir |
&Path | the directory to list |
ext |
&str | the extension without its dot, such as toml |
| returns | std::io::Result<Vec<PathBuf>> | The paths, sorted; empty when dir does not exist. |
fn parse_legacy_artifact
fn parse_legacy_artifact(content: &str, archived: bool) -> Result<LegacyArtifact, String>Parse a legacy artifact file (YAML frontmatter + markdown body).
| Parameter | Type | Description |
|---|---|---|
content |
&str | the whole file |
archived |
bool | whether the file came from artifacts/archive/ |
| returns | Result<LegacyArtifact, String> | The artifact, or a message naming the missing delimiter or field (title, created_at or updated_at). An archived artifact with no archived_at takes its updated_at. |
fn parse_yaml_frontmatter
fn parse_yaml_frontmatter(yaml: &str) -> HashMap<String, String>Read the flat key: value pairs of a frontmatter block, a small subset of YAML.
Quotes around a value are removed. A key with an empty value followed by - item lines
holds the items joined with commas.
| Parameter | Type | Description |
|---|---|---|
yaml |
&str | the text between the --- delimiters |
| returns | HashMap<String, String> | Each key mapped to its value as a string. A key with an empty value and no - item lines is left out. |
fn parse_yaml_list_field
fn parse_yaml_list_field(fields: &HashMap<String, String>, key: &str) -> Vec<String>Split a frontmatter value on commas into a list.
| Parameter | Type | Description |
|---|---|---|
fields |
&HashMap<String, String> | the pairs from [parse_yaml_frontmatter] |
key |
&str | the key to read, such as tags |
| returns | Vec<String> | The trimmed, non-empty items; empty when key is missing. |
struct LegacyArtifact
struct LegacyArtifactParsed legacy artifact data.
| Field | Type | Description |
|---|---|---|
archived_at |
Option<String> | When it was archived; set only for files in artifacts/archive/. |
body |
String | The markdown after the frontmatter. |
_created_at |
String | The created_at frontmatter value; required but not imported. |
id |
Option<String> | The legacy ID from the frontmatter, which links refer to; the file name when absent. |
kind |
Option<String> | The legacy type field, imported as a tag. |
tags |
Vec<String> | Tag labels from the tags list. |
title |
String | The title frontmatter value. |
_updated_at |
String | The updated_at frontmatter value; required, and used as archived_at when that is missing. |
struct LegacyNote
struct LegacyNoteA note embedded in a v0.4 task or iteration TOML file.
| Field | Type | Description |
|---|---|---|
author |
Option<String> | The author’s name; with none, the note has no author. |
author_email |
Option<String> | The author’s email, if recorded. |
author_type |
Option<String> | agent for an agent author; anything else means a human. |
body |
String | The note text. |
Implements Debug, Deserialize<'de>.
struct LegacyLink
struct LegacyLinkA link/relationship embedded in a v0.4 task or iteration TOML file.
| Field | Type | Description |
|---|---|---|
ref_ |
String | The target as <kind>/<id>, such as tasks/abc; the TOML key is ref. |
rel |
String | The relationship type, such as blocks; an unknown one skips the link. |
Implements Debug, Deserialize<'de>.
struct LegacyTask
struct LegacyTaskDeserialization target for legacy task TOML files.
| Field | Type | Description |
|---|---|---|
assigned_to |
Option<String> | The assignee’s name, imported as a human author. |
description |
Option<String> | The task description; empty when absent. |
id |
String | The legacy ID, which links and iterations refer to. |
links |
Option<Vec<LegacyLink>> | Links to other entities. |
metadata |
toml::Table | Free-form metadata, imported as JSON. |
notes |
Option<Vec<LegacyNote>> | Notes on the task. |
priority |
Option<u8> | The priority; lower numbers rank first. |
resolved_at |
Option<String> | When the task was resolved; read but not imported. |
status |
String | The status name; one that does not parse leaves the new task with the default status. |
tags |
Option<Vec<String>> | Tag labels. |
title |
String | The task title. |
Implements Debug, Deserialize<'de>.
struct LegacyIteration
struct LegacyIterationDeserialization target for legacy iteration TOML files.
| Field | Type | Description |
|---|---|---|
description |
Option<String> | The iteration description; empty when absent. |
id |
Option<String> | The legacy ID, which links refer to; the file name when absent. |
links |
Option<Vec<LegacyLink>> | Links to other entities. |
metadata |
toml::Table | Free-form metadata, imported as JSON. |
notes |
Option<Vec<LegacyNote>> | Notes on the iteration. |
tags |
Option<Vec<String>> | Tag labels. |
tasks |
Option<Vec<String>> | Task refs, as tasks/<id> or a bare ID. |
title |
String | The iteration title. |
Implements Debug, Deserialize<'de>.