Two deployments each reported zero newly confirmed migrations. On the promoted PostgreSQL standby, one schema already contained migration 2. The other still needed it. If our deployment agent retried the same SQL whenever it saw zero, it would write a duplicate in the first schema.

I started go-migrate in 2023 as the migration layer of a private Go framework. Like its structured logging layer, it now ships independently. A broken connection during COMMIT gave us a concrete way to test what a deployer can safely infer from the runner’s return value. HaloLog

Make a duplicate observable.

We seeded two schemas at version 1. In each, version 2 inserts the integer 2 into an ordinary table. We deliberately left the column without a uniqueness constraint. An accidental replay could succeed, leaving two copies of 2 and a green deployment. The test therefore reads the application rows as well as the migration history.

A PostgreSQL 17 primary streamed to a synchronous standby with synchronous_commit=remote_apply. The insert and its successful history entry shared one transaction. A connection wrapper interrupted only version 2.

Commit sequence on the runner, primary and standby. One reply is lost after commit. The other transaction loses its primary before commit. After promotion, versions present in the two schemas differ.

Follow migration 2 across the two connections. The original wire diagram was drawn for v1.0.1. The same fixture ran at the v1.1.0 commit. Tagged failover test

Move the fault across COMMIT.

In the first schema, the wrapper read PostgreSQL’s completion message for COMMIT, discarded it, and closed the socket. The caller received ErrCommitOutcomeUnknown and an empty applied list. The fixture waited for the standby to replay through a measured WAL position, then read both the inserted row and its successful history entry on the standby.

In the second schema, the insert and history statements had executed inside the transaction. This time the fixture stopped the primary and verified it had stopped before the driver could send COMMIT. The caller again returned an error and zero confirmed migrations. We then explicitly promoted the standby and opened a fresh Go connection pool with the same multi-host connection string.

Observed on the promoted writer, before retry.

Fault

Caller confirmed

Application rows

Successful history

Fresh plan

Commit reply lost

0

1, 2

1, 2

3

Primary stopped before send

0

1

1

2, 3

Both old plan IDs were rejected with ErrPlanChanged. In the second row, the pending versions were still 2, 3, but the writer had changed. Using fresh target-bound plans, both schemas finished with exactly one copy each of 1, 2 and 3, with matching history. Failover CI at the v1.1.0 commit

Who gets to retry?

The failover test called the Go library directly. Version 1.1.0 addresses a separate decision for an agent using the Model Context Protocol (MCP). The agent can ask the new writer for a plan and send back its ID with confirm: true. On the default MCP server, that request returns operator_approval_required. Knowing what remains to run gives the operator something to review.

The agent obtains a target-bound plan ID. The default MCP process refuses its confirmed request. After operator review, a new process permits one matching attempt, checks the live plan under lock and refuses reuse.

The operator checks the destination, SQL, and callbacks in a trusted environment. A new MCP process can then accept one attempt for the reviewed operation and plan. A lost reply leaves that grant spent.

We exercised this boundary separately on the published Linux and Windows amd64 binaries over MCP stdio, using SQLite. Without a startup grant, both apply and rollback were refused. Fresh database connections confirmed the state after each refusal. With the corresponding grant, each operation ran once, and the same process refused a second attempt. The launcher and its database credentials belong under operator control. Tagged MCP regression

Reproduce the PostgreSQL experiment.

From a disposable checkout of v1.1.0 with Docker, Bash, OpenSSL and a race-enabled Go toolchain, run the fixture. It exercises synchronous physical replication and an explicit promotion. Effects sent to an external service and failover through a managed writer endpoint need their own observations. Fixture script

bash .github/scripts/postgres-failover.sh 

v1.1.0 release · Release build and platform tests · Six-database CI

I maintain go-migrate and used AI to help draft this article.