summaryrefslogtreecommitdiff
path: root/makima/src/db/repository.rs
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src/db/repository.rs')
-rw-r--r--makima/src/db/repository.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs
index 57e8a78..ca07d92 100644
--- a/makima/src/db/repository.rs
+++ b/makima/src/db/repository.rs
@@ -4962,6 +4962,22 @@ pub async fn get_directive_for_owner(
.await
}
+/// Get a directive without an owner scope check.
+///
+/// Used by background orchestration code that has already established the
+/// directive identity through other means (e.g. it just received the
+/// directive_id from a different already-authorized query). HTTP handlers
+/// must continue to use `get_directive_for_owner` to enforce isolation.
+pub async fn get_directive(
+ pool: &PgPool,
+ id: Uuid,
+) -> Result<Option<Directive>, sqlx::Error> {
+ sqlx::query_as::<_, Directive>(r#"SELECT * FROM directives WHERE id = $1"#)
+ .bind(id)
+ .fetch_optional(pool)
+ .await
+}
+
/// Get a directive with all its steps.
pub async fn get_directive_with_steps_for_owner(
pool: &PgPool,
@@ -5637,6 +5653,40 @@ pub async fn update_directive_goal(
.await
}
+/// Update a directive's goal WITHOUT clearing the orchestrator task id.
+///
+/// This is the path used by the goal-edit interrupt cycle: when a small goal
+/// edit arrives while a planner is already running, we want to keep the
+/// planner attached so a `SendMessage` can summarise the change in-flight
+/// instead of cancelling and respawning. We still bump `goal_updated_at` so
+/// the timestamp reflects the edit, but we do NOT trigger replanning by
+/// clearing the orchestrator task. We also do not flip status from
+/// idle/paused → active here, since by definition a planner is already
+/// running.
+pub async fn update_directive_goal_keep_orchestrator(
+ pool: &PgPool,
+ owner_id: Uuid,
+ directive_id: Uuid,
+ goal: &str,
+) -> Result<Option<Directive>, sqlx::Error> {
+ sqlx::query_as::<_, Directive>(
+ r#"
+ UPDATE directives
+ SET goal = $3,
+ goal_updated_at = NOW(),
+ updated_at = NOW(),
+ version = version + 1
+ WHERE id = $1 AND owner_id = $2
+ RETURNING *
+ "#,
+ )
+ .bind(directive_id)
+ .bind(owner_id)
+ .bind(goal)
+ .fetch_optional(pool)
+ .await
+}
+
/// Save a goal to the directive goal history.
pub async fn save_directive_goal_history(
pool: &PgPool,