defmodule ArcadiaCloud.Repo.Migrations.CreateLlmUsageEvents do use Ecto.Migration def change do # `llm_usage_recorded` events received from arcadia-llm-gateway. The # gateway is the LLM-pricing authority — it sends the already-priced # customer charge; arcadia-cloud stores it and rolls it into the # tenant's monthly invoice. Idempotent on gateway_request_id so a # gateway retry never double-bills. create table(:llm_usage_events, primary_key: false) do add :id, :binary_id, primary_key: true add :gateway_request_id, :string, null: false add :tenant_id, :string, null: false add :deployment_id, :string add :provider, :string add :model, :string add :request_kind, :string add :input_tokens, :integer, null: false, default: 0 add :output_tokens, :integer, null: false, default: 0 add :cached_input_tokens, :integer, null: false, default: 0 add :total_tokens, :integer, null: false, default: 0 add :upstream_cost, :decimal add :customer_charge, :decimal add :customer_charge_cents, :integer, null: false, default: 0 add :markup_mode, :string add :occurred_at, :utc_datetime_usec, null: false timestamps(type: :utc_datetime, updated_at: false) end create unique_index(:llm_usage_events, [:gateway_request_id]) create index(:llm_usage_events, [:tenant_id, :occurred_at]) create index(:llm_usage_events, [:deployment_id]) end end