Skip to main content

Module pg_migration

Module pg_migration 

Source
Available on crate feature postgres only.
Expand description

Schema versioning and migration support for PostgresTaskStore.

This module provides a lightweight, forward-only migration runner that tracks applied schema versions in a schema_versions table. Migrations are defined as plain SQL strings and are executed inside transactions for atomicity.

§Built-in migrations

VersionDescription
1Initial schema — tasks table with indexes on context_id and state
2Add composite index on (context_id, state) for combined filter queries
3Add (updated_at DESC, id DESC) index for list ordering
4Add idempotency_keys — the index client-supplied send keys are claimed in
5Add task_events — the per-task log of what the agent emitted
6Add CHECK (seq > 0) to task_events
7Add applied_seq to tasks — the log position each write stores
8Add a2a_task_claims — which replica runs each task’s current turn
9Add the triggers and functions that keep a replica of an earlier release off a task a newer replica runs

This table listed 1 and 2 while five existed. BUILTIN_PG_MIGRATIONS is the list; the test below fails if the two stop agreeing on how many there are.

§Example

use a2a_protocol_server::store::pg_migration::PgMigrationRunner;
use sqlx::postgres::PgPoolOptions;

let pool = PgPoolOptions::new()
    .connect("postgres://user:pass@localhost/a2a")
    .await?;

let runner = PgMigrationRunner::new(pool);
let applied = runner.run_pending().await?;
println!("Applied migrations: {applied:?}");

Structs§

PgMigration
A single schema migration.
PgMigrationRunner
Runs schema migrations against a PostgreSQL database.

Statics§

BUILTIN_PG_MIGRATIONS
Built-in migrations for the PostgresTaskStore schema.