Skip to main content

Migration Tap

Tap streams migration events while Queen runs. It is useful for debugging, CLI live views, tests, and migration reports.

JSON sink

sink := tap.NewJSONSink(os.Stdout)
q := queen.New(postgres.New(db), queen.WithTap(sink))

Events include start, exec, transaction lifecycle events, and end.

Capture Go-function SQL

SQL migrations emit one exec event for the migration SQL. For Go-function migrations, wrap the transaction:

UpFunc: func(ctx context.Context, tx *sql.Tx) error {
t := tap.ObserveTx(ctx, tx)
_, err := t.ExecContext(ctx, `UPDATE users SET email = LOWER(email)`)
return err
}

Analyzer

sink := tap.NewAnalyzerSink(
tap.NewJSONSink(os.Stdout),
tap.DefaultAnalyzerConfig(),
)

The analyzer adds operation names, normalized SQL templates, bound SQL, slow-query markers, and N+1 detection.

Live CLI

go run ./cmd/migrate up --tap --driver postgres --dsn "$DATABASE_URL"

Tune thresholds:

go run ./cmd/migrate up --tap \
--tap-slow-threshold 250ms \
--tap-nplus1-threshold 10