Flyway has no @Migration annotation. Flyway discovers migrations by file name (for SQL) or by implementing an interface (for Java), so there is nothing to annotate. The idea that @Migration marks a method as a migration step does not match the Flyway API.
For migrations written in Java, you extend BaseJavaMigration (or implement JavaMigration) and name the class with the same convention as SQL files, such as V2__Backfill_slugs. Flyway then orders, records and runs it like any other versioned migration.
Flyway scans its configured locations (by default classpath:db/migration) and recognises two kinds of migrations:
V1__Create_users.sql, V2__Add_email.sql for versioned migrations, R__Refresh_views.sql for repeatable ones.JavaMigration.The name encodes the version (V2, V2.1), a double underscore, and a description. Flyway stores each applied migration with a checksum in the flyway_schema_history table and refuses to run if an already applied migration changed.
| Migration kind | Name pattern | Runs |
|---|---|---|
| Versioned | V<version>__<description> | Once, in version order |
| Repeatable | R__<description> | Again whenever its checksum changes, after versioned ones |
| Undo (Teams edition) | U<version>__<description> | On explicit undo |
Use a Java migration when SQL is not enough, for example to transform data with application logic.
The version (2) and description (Backfill slugs) come from the class name. You can override getVersion() and related methods if you need a different scheme. Flyway runs the code on a connection it manages, inside a transaction where the database supports transactional DDL.
Spring Boot runs Flyway automatically at startup when flyway-core (and, for newer databases, the matching flyway-database-* module) is on the classpath.
Place V1__init.sql in src/main/resources/db/migration and Java migrations in the db.migration package, which lies in the scanned classpath location. Java migrations that need Spring beans can be registered as beans, since Boot passes JavaMigration beans to Flyway.
Some tools do use annotations, which may be the source of the confusion:
@Transactional can wrap your own migration service code.@Migration annotation either.[Migration] attribute, but that is a C# feature, not Flyway.flyway validate (or mvn flyway:validate) in CI to catch checksum drift.No. SQL migrations are identified by file name and Java migrations by implementing JavaMigration, usually through BaseJavaMigration.
Create a class named V<version>__<Description> that extends BaseJavaMigration, implement migrate(Context), and place it in a scanned package such as db.migration.
It records every applied migration in the flyway_schema_history table, with version, description and checksum.
Yes. They share one version sequence, so V1__init.sql can be followed by V2__Backfill_slugs.java.
Flyway does not use an @Migration annotation. Name SQL files with the V<version>__<description> convention, or extend BaseJavaMigration for Java logic, and let Flyway track everything in flyway_schema_history. Keep applied migrations immutable and validate them in CI.