summaryrefslogtreecommitdiff
path: root/makima/src/db/repository.rs
diff options
context:
space:
mode:
authorsoryu <soryu@soryu.co>2026-02-08 16:18:13 +0000
committersoryu <soryu@soryu.co>2026-02-08 16:18:13 +0000
commitc0f220582cd61f0d88e42dfbc29d55b3be1e3b19 (patch)
tree5105fe5ffb6e80d3e82f806411628b0587c0685c /makima/src/db/repository.rs
parent62d411f61893486680ded5921a8b86b483ee1144 (diff)
downloadsoryu-c0f220582cd61f0d88e42dfbc29d55b3be1e3b19.tar.gz
soryu-c0f220582cd61f0d88e42dfbc29d55b3be1e3b19.zip
Fix directive deletion and stop local only on contracts
Diffstat (limited to 'makima/src/db/repository.rs')
-rw-r--r--makima/src/db/repository.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs
index 63493b9..6b3f15f 100644
--- a/makima/src/db/repository.rs
+++ b/makima/src/db/repository.rs
@@ -5130,11 +5130,32 @@ pub async fn update_directive_for_owner(
}
/// Delete a directive by ID, scoped to owner.
+/// Also deletes all contracts (and their cascaded tasks/files) associated with this directive.
pub async fn delete_directive_for_owner(
pool: &PgPool,
id: Uuid,
owner_id: Uuid,
) -> Result<bool, sqlx::Error> {
+ // First verify the directive exists and belongs to the owner
+ let directive = get_directive_for_owner(pool, id, owner_id).await?;
+ let Some(_directive) = directive else {
+ return Ok(false);
+ };
+
+ // Delete all contracts linked to this directive (tasks/files cascade from contracts).
+ // This covers step contracts (directive_id FK) and the orchestrator contract.
+ sqlx::query(
+ r#"
+ DELETE FROM contracts
+ WHERE directive_id = $1
+ OR id = (SELECT orchestrator_contract_id FROM directives WHERE id = $1)
+ "#,
+ )
+ .bind(id)
+ .execute(pool)
+ .await?;
+
+ // Now delete the directive itself (chains, steps, events, evaluations cascade via FK)
let result = sqlx::query(
r#"
DELETE FROM directives