Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

# Migration to add composite indexes for dashboard query performance
#
# These indexes optimize the most frequent dashboard queries:
# - [status, created_at]: now_strip_data conditional counts, error spike detection, top_errors
# - [model_id, status]: model_stats GROUP BY with success count
# - [cache_hit, created_at]: cache_savings queries
class AddDashboardPerformanceIndexes < ActiveRecord::Migration[8.1]
def change
add_index :ruby_llm_agents_executions, [:status, :created_at],
name: "idx_executions_status_created_at",
if_not_exists: true

add_index :ruby_llm_agents_executions, [:model_id, :status],
name: "idx_executions_model_id_status",
if_not_exists: true

add_index :ruby_llm_agents_executions, [:cache_hit, :created_at],
name: "idx_executions_cache_hit_created_at",
if_not_exists: true
end
end
17 changes: 10 additions & 7 deletions example/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.1].define(version: 2026_02_16_182104) do
ActiveRecord::Schema[8.1].define(version: 2026_03_06_000001) do
create_table "organizations", force: :cascade do |t|
t.boolean "active", default: true
t.string "anthropic_api_key"
Expand Down Expand Up @@ -51,43 +51,46 @@

create_table "ruby_llm_agents_executions", force: :cascade do |t|
t.string "agent_type", null: false
t.integer "attempts_count", default: 0, null: false
t.integer "attempts_count", default: 1, null: false
t.boolean "cache_hit", default: false
t.integer "cached_tokens", default: 0
t.string "chosen_model_id"
t.datetime "completed_at"
t.datetime "created_at", null: false
t.integer "duration_ms"
t.string "error_class"
t.string "execution_type", default: "chat"
t.string "execution_type", default: "chat", null: false
t.string "finish_reason"
t.decimal "input_cost", precision: 12, scale: 6
t.integer "input_tokens"
t.integer "input_tokens", default: 0
t.integer "messages_count", default: 0, null: false
t.json "metadata", default: {}, null: false
t.string "model_id", null: false
t.string "model_provider"
t.decimal "output_cost", precision: 12, scale: 6
t.integer "output_tokens"
t.integer "output_tokens", default: 0
t.bigint "parent_execution_id"
t.string "request_id"
t.bigint "root_execution_id"
t.datetime "started_at", null: false
t.string "status", default: "success", null: false
t.string "status", default: "running", null: false
t.boolean "streaming", default: false
t.decimal "temperature", precision: 3, scale: 2
t.string "tenant_id"
t.integer "tool_calls_count", default: 0, null: false
t.decimal "total_cost", precision: 12, scale: 6
t.integer "total_tokens"
t.integer "total_tokens", default: 0
t.string "trace_id"
t.datetime "updated_at", null: false
t.index ["agent_type", "created_at"], name: "index_ruby_llm_agents_executions_on_agent_type_and_created_at"
t.index ["agent_type", "status"], name: "index_ruby_llm_agents_executions_on_agent_type_and_status"
t.index ["cache_hit", "created_at"], name: "idx_executions_cache_hit_created_at"
t.index ["created_at"], name: "index_ruby_llm_agents_executions_on_created_at"
t.index ["model_id", "status"], name: "idx_executions_model_id_status"
t.index ["parent_execution_id"], name: "index_ruby_llm_agents_executions_on_parent_execution_id"
t.index ["request_id"], name: "index_ruby_llm_agents_executions_on_request_id"
t.index ["root_execution_id"], name: "index_ruby_llm_agents_executions_on_root_execution_id"
t.index ["status", "created_at"], name: "idx_executions_status_created_at"
t.index ["status"], name: "index_ruby_llm_agents_executions_on_status"
t.index ["tenant_id", "agent_type"], name: "index_ruby_llm_agents_executions_on_tenant_id_and_agent_type"
t.index ["tenant_id", "created_at"], name: "index_ruby_llm_agents_executions_on_tenant_id_and_created_at"
Expand Down
Loading