Module: LlmCostTracker::Ledger::Schema::ProviderInvoices

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

Constant Summary collapse

REQUIRED_COLUMNS =
%w[
  source period_start period_end external_id billed_amount currency metadata imported_at
].freeze
UNIQUE_INDEX_COLUMNS =
%i[external_id].freeze
SOURCE_PERIOD_INDEX_COLUMNS =
%i[source currency period_start].freeze

Class Method Summary collapse

Class Method Details

.current_schema_errorsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/llm_cost_tracker/ledger/schema/provider_invoices.rb', line 16

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

  columns = LlmCostTracker::ProviderInvoice.columns_hash
  cache = @schema_capabilities
  return cache.fetch(:errors) if cache && cache.fetch(:columns).equal?(columns)

  errors = compute_errors(connection, table_name, columns)
  @schema_capabilities = { columns: columns, errors: errors }
  errors
end