diff options
Diffstat (limited to 'makima/src/db/repository.rs')
| -rw-r--r-- | makima/src/db/repository.rs | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs index 9cb653f..7be7bc8 100644 --- a/makima/src/db/repository.rs +++ b/makima/src/db/repository.rs @@ -5162,7 +5162,8 @@ pub async fn list_chain_contracts( cc.editor_y, cc.evaluation_status, cc.evaluation_retry_count, - cc.max_evaluation_retries + cc.max_evaluation_retries, + cc.created_at FROM chain_contracts cc JOIN contracts c ON c.id = cc.contract_id WHERE cc.chain_id = $1 @@ -6266,6 +6267,45 @@ async fn create_contract_from_definition( .execute(pool) .await?; + // Copy repositories from chain to contract + let chain_repos = list_chain_repositories(pool, chain_id).await.unwrap_or_default(); + for repo in chain_repos { + if let Some(url) = &repo.repository_url { + // Remote repository + if let Err(e) = add_remote_repository(pool, contract.id, &repo.name, url, repo.is_primary).await { + tracing::warn!( + contract_id = %contract.id, + repo_name = %repo.name, + error = %e, + "Failed to copy repository from chain to contract" + ); + } + } else if let Some(path) = &repo.local_path { + // Local repository + if let Err(e) = add_local_repository(pool, contract.id, &repo.name, path, repo.is_primary).await { + tracing::warn!( + contract_id = %contract.id, + repo_name = %repo.name, + error = %e, + "Failed to copy local repository from chain to contract" + ); + } + } + } + + // Activate the contract so it can start + sqlx::query("UPDATE contracts SET status = 'active' WHERE id = $1") + .bind(contract.id) + .execute(pool) + .await?; + + tracing::info!( + contract_id = %contract.id, + contract_name = %def.name, + chain_id = %chain_id, + "Contract created and activated from chain definition" + ); + Ok(contract.id) } |
