diff --git a/backend/migrations/009_change_executor_config_to_executor.sql b/backend/migrations/009_change_executor_config_to_executor.sql new file mode 100644 index 00000000..3ef1f49a --- /dev/null +++ b/backend/migrations/009_change_executor_config_to_executor.sql @@ -0,0 +1,18 @@ +-- Change executor_config column to executor (string) in task_attempts table + +-- Add the new executor column +ALTER TABLE task_attempts ADD COLUMN executor TEXT; + +-- Convert existing executor_config data to executor names +-- This assumes the existing JSONB data has a structure we can extract from +UPDATE task_attempts +SET executor = CASE + WHEN executor_config IS NULL THEN NULL + WHEN executor_config->>'type' = 'Echo' THEN 'echo' + WHEN executor_config->>'type' = 'Claude' THEN 'claude' + ELSE 'echo' -- Default fallback +END +WHERE executor_config IS NOT NULL; + +-- Drop the old executor_config column +ALTER TABLE task_attempts DROP COLUMN executor_config; diff --git a/backend/src/models/task_attempt.rs b/backend/src/models/task_attempt.rs index dce12527..7c8a635c 100644 --- a/backend/src/models/task_attempt.rs +++ b/backend/src/models/task_attempt.rs @@ -62,8 +62,7 @@ pub struct TaskAttempt { pub base_commit: Option, pub merge_commit: Option, #[serde(skip_serializing_if = "Option::is_none")] - #[ts(skip)] - pub executor_config: Option, // JSON field for ExecutorConfig + pub executor: Option, // Name of the executor to use pub stdout: Option, pub stderr: Option, pub created_at: DateTime, @@ -77,7 +76,7 @@ pub struct CreateTaskAttempt { pub worktree_path: String, pub base_commit: Option, pub merge_commit: Option, - pub executor_config: Option, + pub executor: Option, } #[derive(Debug, Deserialize, TS)] @@ -92,7 +91,7 @@ impl TaskAttempt { pub async fn find_by_id(pool: &PgPool, id: Uuid) -> Result, sqlx::Error> { sqlx::query_as!( TaskAttempt, - r#"SELECT id, task_id, worktree_path, base_commit, merge_commit, executor_config, stdout, stderr, created_at, updated_at + r#"SELECT id, task_id, worktree_path, base_commit, merge_commit, executor, stdout, stderr, created_at, updated_at FROM task_attempts WHERE id = $1"#, id @@ -104,7 +103,7 @@ impl TaskAttempt { pub async fn find_by_task_id(pool: &PgPool, task_id: Uuid) -> Result, sqlx::Error> { sqlx::query_as!( TaskAttempt, - r#"SELECT id, task_id, worktree_path, base_commit, merge_commit, executor_config, stdout, stderr, created_at, updated_at + r#"SELECT id, task_id, worktree_path, base_commit, merge_commit, executor, stdout, stderr, created_at, updated_at FROM task_attempts WHERE task_id = $1 ORDER BY created_at DESC"#, @@ -138,24 +137,18 @@ impl TaskAttempt { let branch_name = format!("attempt-{}", attempt_id); repo.worktree(&branch_name, worktree_path, None)?; - // Serialize executor config to JSON - let executor_config_json = data.executor_config.as_ref() - .map(|config| serde_json::to_value(config)) - .transpose() - .map_err(|e| TaskAttemptError::Database(sqlx::Error::decode(e)))?; - // Insert the record into the database let task_attempt = sqlx::query_as!( TaskAttempt, - r#"INSERT INTO task_attempts (id, task_id, worktree_path, base_commit, merge_commit, executor_config, stdout, stderr) + r#"INSERT INTO task_attempts (id, task_id, worktree_path, base_commit, merge_commit, executor, stdout, stderr) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) - RETURNING id, task_id, worktree_path, base_commit, merge_commit, executor_config, stdout, stderr, created_at, updated_at"#, + RETURNING id, task_id, worktree_path, base_commit, merge_commit, executor, stdout, stderr, created_at, updated_at"#, attempt_id, data.task_id, data.worktree_path, data.base_commit, data.merge_commit, - executor_config_json, + data.executor, None::, // stdout None:: // stderr ) @@ -181,13 +174,16 @@ impl TaskAttempt { /// Get the executor for this task attempt, defaulting to Echo if none is specified pub fn get_executor(&self) -> Box { - if let Some(config_json) = &self.executor_config { - if let Ok(config) = serde_json::from_value::(config_json.clone()) { - return config.create_executor(); + if let Some(executor_name) = &self.executor { + match executor_name.as_str() { + "echo" => ExecutorConfig::Echo.create_executor(), + "claude" => ExecutorConfig::Claude.create_executor(), + _ => ExecutorConfig::Echo.create_executor(), // Default fallback } + } else { + // Default to echo executor + ExecutorConfig::Echo.create_executor() } - // Default to echo executor - ExecutorConfig::Echo.create_executor() } /// Update stdout and stderr for this task attempt