diff options
Diffstat (limited to 'makima/src')
| -rw-r--r-- | makima/src/db/repository.rs | 21 | ||||
| -rw-r--r-- | makima/src/orchestration/directive.rs | 9 |
2 files changed, 27 insertions, 3 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 diff --git a/makima/src/orchestration/directive.rs b/makima/src/orchestration/directive.rs index 80e2a8b..044fce6 100644 --- a/makima/src/orchestration/directive.rs +++ b/makima/src/orchestration/directive.rs @@ -758,7 +758,10 @@ async fn dispatch_step( .await .map_err(|e| format!("Failed to update step status: {}", e))?; - // Create contract for this step + // Create contract for this step. + // Step contracts use the directive's repository config — not local_only, + // so they can branch and merge to share work across steps. + let has_repo = directive.repository_url.is_some() || directive.local_path.is_some(); let contract = repository::create_contract_for_owner( pool, owner_id, @@ -770,8 +773,8 @@ async fn dispatch_step( initial_phase: step.initial_phase.clone(), autonomous_loop: Some(true), phase_guard: None, - local_only: Some(true), - auto_merge_local: None, + local_only: Some(!has_repo), + auto_merge_local: if has_repo { Some(true) } else { None }, }, ) .await |
