# Quick script to check if newly created risk hits have action history # Run with: mix run check_new_hits_action_history.exs alias PlatformCore.Repo alias RiskCore.Context alias RiskCore.RiskRuleHit import Ecto.Query IO.puts("\nšŸ” Checking action history for newly created risk hits...\n") # Find the most recent 3 risk hits recent_hits = Repo.all( from h in RiskRuleHit, order_by: [desc: h.inserted_at], limit: 3, select: %{id: h.id, status: h.status, inserted_at: h.inserted_at, metadata: h.metadata} ) Enum.each(recent_hits, fn hit -> IO.puts("Risk Hit ID: #{hit.id}") IO.puts(" Status: #{hit.status}") IO.puts(" Created: #{Calendar.strftime(hit.inserted_at, "%Y-%m-%d %H:%M:%S")}") # Check if metadata has action_history action_history = Context.get_hit_action_history(hit.id) if length(action_history) > 0 do IO.puts(" āœ… Has #{length(action_history)} action(s) in history:") Enum.each(action_history, fn action -> timestamp_str = if action.timestamp do Calendar.strftime(action.timestamp, "%Y-%m-%d %H:%M:%S") else "N/A" end IO.puts(" - #{action.action} at #{timestamp_str} (#{action.from_status || "N/A"} → #{action.to_status})") end) else IO.puts(" āš ļø No action history (legacy data - created before feature was implemented)") end IO.puts("") end) IO.puts("Note: New transactions created after the action history feature will have") IO.puts(" a 'Created' system action automatically recorded.\n")