Module: LlmCostTracker::Ledger::Schema::CallRollups

Defined in:
lib/llm_cost_tracker/ledger/schema/call_rollups.rb

Constant Summary collapse

REQUIRED_COLUMNS =
%w[period period_start currency total_cost].freeze
UNIQUE_COLUMNS =
%i[period period_start currency].freeze

Class Method Summary collapse

Class Method Details

.current_schema_errorsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/llm_cost_tracker/ledger/schema/call_rollups.rb', line 13

def current_schema_errors
  connection = LlmCostTracker::CallRollup.connection
  Adapter.ensure_supported!(connection)
  table_name = LlmCostTracker::CallRollup.table_name
  return ["#{table_name} table is missing"] unless connection.data_source_exists?(table_name)

  errors = []
  missing = REQUIRED_COLUMNS - LlmCostTracker::CallRollup.columns_hash.keys
  errors << "missing columns: #{missing.join(', ')}" if missing.any?
  unless unique_period_index?(connection, table_name)
    errors << "missing unique index: period, period_start, currency"
  end
  errors
end