Skip to content

Non-transactional migrations, callbacks, and superseded repeatables#2

Merged
cgardev merged 1 commit into
mainfrom
feature/flyway-parity
May 31, 2026
Merged

Non-transactional migrations, callbacks, and superseded repeatables#2
cgardev merged 1 commit into
mainfrom
feature/flyway-parity

Conversation

@cgardev

@cgardev cgardev commented May 31, 2026

Copy link
Copy Markdown
Owner

Closes #1.

Implements the three missing Flyway behaviors, each developed with TDD (unit tests first) and verified with integration tests against real PostgreSQL (testcontainers) and SQLite.

1. Per-script non-transactional execution

A script whose first comment lines carry -- goway:noTransaction (the -- flyway:executeInTransaction=false form is also accepted) runs outside the per-migration transaction, on a dedicated connection.

  • Enables CREATE INDEX CONCURRENTLY (PostgreSQL) and VACUUM (SQLite).
  • New sessionSearchPathSQL dialect method sets the schema for the session.
  • A failure records a failed history row (no transaction to roll back) that Repair can clear.

2. Callbacks

  • SQL callback scripts discovered by file name: beforeMigrate.sql, afterMigrate.sql, beforeEachMigrate.sql, afterEachMigrate__desc.sql.
  • Programmatic callbacks via Configure().Callbacks(...), the Callback interface, and the CallbackFunc adapter.
  • Per-migration callbacks run on the same executor (transaction) as the migration.

3. Superseded state for repeatables

  • Info keeps every applied run of a repeatable migration.
  • Newest run by installed_rank is current (Success/Outdated); older runs are StateSuperseded.
  • Superseded is never a validation error.

Tests

  • Unit: script_test.go, callback_test.go, info_superseded_test.go (+ existing suite) — all green.
  • Integration: integration/parity_test.go adds 6 tests (PostgreSQL concurrent index + control, SQLite vacuum, SQL callbacks, programmatic callbacks, repeatable supersede). Full suite: 21 pass, 0 fail.
  • Core stays zero-dependency; CLI and example build.

Docs

README "Status and roadmap" updated; new Callbacks and Non-transactional sections in README and docs/design.md.

…bles

Closes #1.

Add three Flyway behaviors, each with unit and integration tests:

1. Per-script non-transactional execution. A script whose first comment lines
   carry a "-- goway:noTransaction" directive runs outside the per-migration
   transaction on a dedicated connection, enabling statements such as
   PostgreSQL's CREATE INDEX CONCURRENTLY and SQLite's VACUUM. A new
   sessionSearchPathSQL dialect method sets the schema for such runs.

2. Lifecycle callbacks. SQL callback scripts (beforeMigrate, afterMigrate,
   beforeEachMigrate, afterEachMigrate) are discovered in the configured
   locations, and callbacks can also be registered programmatically through the
   Callback interface and the CallbackFunc adapter.

3. Superseded state for repeatable migrations. Info now keeps every applied run
   of a repeatable migration; the newest by installed rank is current and the
   older runs are reported as Superseded, which is never a validation error.

Update the README and design documentation accordingly.
@cgardev cgardev merged commit 401d5f0 into main May 31, 2026
4 checks passed
@cgardev cgardev deleted the feature/flyway-parity branch May 31, 2026 12:50
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.

Add per-script non-transactional execution, callbacks, and Superseded state for repeatables

1 participant