Baton.Migration (Baton v0.27.4)

Copy Markdown View Source

Installs and updates Baton's database schema.

Like Oban, Baton ships its tables as a versioned migration the host invokes from its own migration file:

defmodule MyApp.Repo.Migrations.AddBaton do
  use Ecto.Migration

  def up,   do: Baton.Migration.up(version: 1)
  def down, do: Baton.Migration.down(version: 1)
end

Future schema changes ship as higher versions; bumping the version: and running mix ecto.migrate upgrades in place. Calls are idempotent (create_if_not_exists), so re-running is safe.

Options

  • :version — target schema version (default: latest)
  • :prefix — Postgres schema prefix (matches your Oban prefix, if any)

Tables

  • workflow_nodes — workflow membership, dependencies, and step results
  • workflow_step_stats — per-step LLM token/cost stats (optional feature)
  • workflow_debug_logs — captured request/response payloads (optional feature)
  • workflow_completions — one row per finished workflow; the claim that makes the terminal {:workflow_finished, _} notification fire exactly once (v2)
  • workflow_artifacts — large step results spilled out of workflow_nodes to keep the hot dependency-gating table small (v3)

workflow_nodes.sequence_after (v6) records the sequential fan-out gate's ordering edge, which is deliberately not a dependency — see Baton.Check.

workflow_nodes.checkpoint (v7) is engine scratch space for a step that spans multiple attempts — the batch id a mode: :batch LLM step polls for. Unlike result it is never visible to dependents and never means the step finished; see Baton.Results.store_checkpoint/2.

Indexes on oban_jobs

v4 adds a partial expression index on oban_jobs ((meta->>'workflow_id')), restricted to workflow jobs. It backs the plugin's failed-workflow detection (a GROUP BY meta->>'workflow_id') and the orphan-rescue scan, so those sweeps stay cheap as oban_jobs grows and can run on a short interval without pressuring the table.

Summary

Functions

Roll back down to :version (default: remove everything).

Migrate up to :version (default: latest).

Functions

down(opts \\ [])

Roll back down to :version (default: remove everything).

up(opts \\ [])

Migrate up to :version (default: latest).