diff options
| author | soryu <soryu@soryu.co> | 2026-02-07 23:48:51 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-02-07 23:48:51 +0000 |
| commit | f0a92073702d614302deff5e83c14ffec3ae6db0 (patch) | |
| tree | 4bb8bf86342deeeea6b801a3df9c1048c20f48d5 /makima/src/db | |
| parent | 89ccd1375c2eaddd1f2b74a42b2d152c83b346e8 (diff) | |
| download | soryu-f0a92073702d614302deff5e83c14ffec3ae6db0.tar.gz soryu-f0a92073702d614302deff5e83c14ffec3ae6db0.zip | |
Fixes for directive chain creation
Diffstat (limited to 'makima/src/db')
| -rw-r--r-- | makima/src/db/repository.rs | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs index d50ef61..177aed3 100644 --- a/makima/src/db/repository.rs +++ b/makima/src/db/repository.rs @@ -5299,7 +5299,7 @@ pub async fn create_directive_chain( sqlx::query_as::<_, DirectiveChain>( r#" INSERT INTO directive_chains (directive_id, generation, name, description, rationale, total_steps, status) - VALUES ($1, $2, $3, $4, $5, $6, 'active') + VALUES ($1, $2, $3, $4, $5, $6, 'running') RETURNING * "#, ) @@ -5346,6 +5346,47 @@ pub async fn create_chain_step( .await } +/// Get a single chain step by ID. +pub async fn get_chain_step( + pool: &PgPool, + step_id: Uuid, +) -> Result<Option<ChainStep>, sqlx::Error> { + sqlx::query_as::<_, ChainStep>( + "SELECT * FROM chain_steps WHERE id = $1", + ) + .bind(step_id) + .fetch_optional(pool) + .await +} + +/// Increment completed_steps counter on a directive chain. +pub async fn increment_chain_completed_steps( + pool: &PgPool, + chain_id: Uuid, +) -> Result<(), sqlx::Error> { + sqlx::query( + "UPDATE directive_chains SET completed_steps = completed_steps + 1, updated_at = NOW() WHERE id = $1", + ) + .bind(chain_id) + .execute(pool) + .await?; + Ok(()) +} + +/// Increment failed_steps counter on a directive chain. +pub async fn increment_chain_failed_steps( + pool: &PgPool, + chain_id: Uuid, +) -> Result<(), sqlx::Error> { + sqlx::query( + "UPDATE directive_chains SET failed_steps = failed_steps + 1, updated_at = NOW() WHERE id = $1", + ) + .bind(chain_id) + .execute(pool) + .await?; + Ok(()) +} + /// Update a chain step's status with automatic timestamp management. pub async fn update_step_status( pool: &PgPool, @@ -5574,6 +5615,19 @@ pub async fn list_evaluations_for_step( .await } +/// Get a single directive evaluation by ID. +pub async fn get_directive_evaluation( + pool: &PgPool, + evaluation_id: Uuid, +) -> Result<Option<DirectiveEvaluation>, sqlx::Error> { + sqlx::query_as::<_, DirectiveEvaluation>( + "SELECT * FROM directive_evaluations WHERE id = $1", + ) + .bind(evaluation_id) + .fetch_optional(pool) + .await +} + /// Create a directive event. pub async fn create_directive_event( pool: &PgPool, |
