Skip to content

feat(migrate): trace migrations and initialize CLI logging - #4519

Open
shuvroroy wants to merge 4 commits into
transact-rs:mainfrom
shuvroroy:feat/4509-migration-logging
Open

shuvroroy wants to merge 4 commits into
transact-rs:mainfrom
shuvroroy:feat/4509-migration-logging

Conversation

@shuvroroy

@shuvroroy shuvroroy commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Migrations now emit structured sqlx::migrate tracing events before execution and on success or failure. Events include the migration version, description, and direction; successful completions also include the execution time. Instrumenting the built-in drivers gives Migrator, direct Migrate calls, AnyConnection, and the CLI the same behavior.

Both CLI binaries initialize a tracing subscriber after loading .env. Logs go to stderr with a default level of warn; RUST_LOG=sqlx::migrate=info enables migration progress logging. Existing status output stays on stdout. Already applied migrations, skips, dry runs, and validation failures do not emit execution events.

Does your PR solve an issue?

Fixes #4509 by implementing migration logging as suggested in the maintainer's response.

Is this a breaking change?

No public SQLx API or migration execution changes. The CLI now emits warnings and errors to stderr by default, with filtering controlled by RUST_LOG.

Validation

  • Reproduced the CI failures locally with certificate-based TLS. After preserving the original DATABASE_URL, migration suites pass with PostgreSQL 17 CA verification and MySQL 8/MariaDB 11.4 client certificate paths using Smol and Rustls, plus SQLite.
  • Migration integration suites pass on SQLite (9 tests), PostgreSQL 15 (8), MySQL 8 (7), and MariaDB 11.4 (7), including native and AnyConnection coverage.
  • Tests cover apply/revert success and failure, transaction options, target versions, repeated runs, skips, and validation failures. A separate assertion verifies that the start event is emitted before execution is polled.
  • Confirmed the migration logging regression test fails with zero captured events when driver instrumentation is removed, and passes after restoration.
  • Embedded migration compatibility test passes.
  • Full sqlx-cli suite passes (17 tests), including both binaries, stderr output, filters, .env, --no-dotenv, dry runs, skips, and failed migrations.
  • Clippy passes for the affected libraries and migration integration tests with the repository's normal settings. CLI libraries, binaries, and logging tests also pass with -D warnings. Applying -D warnings to the database integration targets encounters the existing clippy::needless_question_mark warning in sqlx-test/src/lib.rs:20.
  • cargo fmt --all --check and git diff --check pass.

@shuvroroy
shuvroroy marked this pull request as ready for review November 11, 2026 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please support a callback when applying a migration

1 participant