ExAgent.Migration (ExAgent v3.0.0)

View Source

Versioned PostgreSQL schema for the bundled ExAgent adapters.

Stability — Stable.

Call from a transactional host Ecto migration. A fresh installation or enrollment of a 2.x schema pins version 1 on the way up and 0 on the way down.

def up, do: ExAgent.Migration.up(version: 1)
def down, do: ExAgent.Migration.down(version: 0)

The version sequence is append-only. Once a version is published, its DDL stays fixed in both directions. Schema changes use a new version. Pin the version in the migration file so it can be replayed with later releases.

Version 1 installs the Store schema including the pending timer and retention indexes, and the Jobs, Budget, RateLimiter, Memory, ResultStore and follow-up relations. Oban and host application tables have their own migrations. The Repo's first schema on its search path owns the installation. An alternate Ecto prefix must match that schema.

Set :table for a custom snapshots table and :memory_table for a custom Memory table. A custom snapshots table is installed alongside the default table used by durable Jobs. Use the same options in both directions. exagent_follow_ups is reserved for scheduled follow-ups.

Existing 2.x schemas can be enrolled in place. After the migration commits, run ExAgent.Store.Postgres.rebuild_run_headers/1 and ExAgent.Store.Postgres.verify_run_headers/1 with the deployed Repo descriptor for each enrolled Store table with 2.x C7 journals. Complete this step before starting writers and Recovery. Enrollment starts at write format level 1 for both new and existing tables.

Summary

Functions

The latest unified schema version in this release.

Roll back to the target :version, which defaults to 0. Stop writers and settle or cancel scheduled follow-ups and open timers in every enrolled Store first. Version 0 removes enrollment and empty tables created by the unified migration, plus the pending timer and retention indexes on adopted Stores. Adopted tables and their other additive schema repairs are preserved. Rollback refuses to undo a finalized format level.

Read the applied unified schema version on the Repo's search path. Returns 0 for a fresh or legacy schema. Pass :repo outside an Ecto migration and optionally :table to check a specific Store.

Install up to the target :version, inclusive. Defaults to the latest version.

Functions

current_version()

@spec current_version() :: pos_integer()

The latest unified schema version in this release.

down(opts \\ [])

@spec down(keyword()) :: :ok

Roll back to the target :version, which defaults to 0. Stop writers and settle or cancel scheduled follow-ups and open timers in every enrolled Store first. Version 0 removes enrollment and empty tables created by the unified migration, plus the pending timer and retention indexes on adopted Stores. Adopted tables and their other additive schema repairs are preserved. Rollback refuses to undo a finalized format level.

migrated_version(opts \\ [])

@spec migrated_version(keyword()) :: non_neg_integer()

Read the applied unified schema version on the Repo's search path. Returns 0 for a fresh or legacy schema. Pass :repo outside an Ecto migration and optionally :table to check a specific Store.

up(opts \\ [])

@spec up(keyword()) :: :ok

Install up to the target :version, inclusive. Defaults to the latest version.