-- name: runtimedeploytask__reset_desired_to_pending :one
UPDATE runtime_deploy_tasks
SET
    runtime_mode = $2,
    namespace = $3,
    target_env = $4,
    slot_no = $5,
    repository_full_name = $6,
    services_yaml_path = $7,
    build_ref = $8,
    deploy_only = $9,
    status = 'pending',
    lease_owner = NULL,
    lease_until = NULL,
    attempts = 0,
    last_error = NULL,
    result_namespace = NULL,
    result_target_env = NULL,
    cancel_requested_at = NULL,
    cancel_requested_by = NULL,
    cancel_reason = NULL,
    stop_requested_at = NULL,
    stop_requested_by = NULL,
    stop_reason = NULL,
    terminal_status_source = NULL,
    terminal_event_seq = 0,
    logs_json = '[]'::jsonb,
    started_at = NULL,
    finished_at = NULL,
    updated_at = NOW()
WHERE run_id = $1::uuid
RETURNING
    run_id::text AS run_id,
    runtime_mode,
    namespace,
    target_env,
    slot_no,
    repository_full_name,
    services_yaml_path,
    build_ref,
    deploy_only,
    status,
    COALESCE(lease_owner, '') AS lease_owner,
    lease_until,
    attempts,
    COALESCE(last_error, '') AS last_error,
    COALESCE(result_namespace, '') AS result_namespace,
    COALESCE(result_target_env, '') AS result_target_env,
    cancel_requested_at,
    COALESCE(cancel_requested_by, '') AS cancel_requested_by,
    COALESCE(cancel_reason, '') AS cancel_reason,
    stop_requested_at,
    COALESCE(stop_requested_by, '') AS stop_requested_by,
    COALESCE(stop_reason, '') AS stop_reason,
    COALESCE(terminal_status_source, '') AS terminal_status_source,
    terminal_event_seq,
    created_at,
    updated_at,
    started_at,
    finished_at,
    COALESCE(logs_json, '[]'::jsonb) AS logs_json;
