Flyway has no @SqlMigration annotation. If you have seen it in a tutorial or an AI-generated answer, it is not part of the Flyway API. Flyway finds SQL migrations by file name and location, and it runs Java migrations through classes that implement JavaMigration (usually by extending BaseJavaMigration).
This article explains how migrations are actually declared, named and registered, including with Spring Boot.
Flyway discovers migrations by convention, not annotation. A SQL migration is a plain .sql file whose name carries the version, and Flyway scans the configured locations for it. Because the file name already defines the version and description, an annotation would add nothing.
The pieces you will really use are:
| Need | Flyway mechanism |
|---|---|
| Versioned SQL change | File named V<version>__<description>.sql |
| Repeatable SQL change | File named R__<description>.sql |
| Java migration | Class extending BaseJavaMigration |
| Lifecycle hooks | Callbacks such as beforeMigrate.sql or a Callback class |
| Undo scripts | U<version>__<description>.sql (paid editions only) |
The default pattern is a prefix, a version, two underscores, a description and the .sql suffix.
flyway_schema_history table with a checksum.An example versioned migration:
Use Java when a change needs logic that SQL cannot express well, such as transforming data row by row. Extend BaseJavaMigration; the class name decides the version, using the same convention, for example V3__EncryptPhoneNumbers.
Put it in a package under a scanned location, by default db/migration on the classpath, which for Java classes means the db.migration package.
Spring Boot runs Flyway on startup when flyway-core is on the classpath and a DataSource exists.
Since Flyway 10, database support lives in separate modules, so add the module for your database (the PostgreSQL one is shown). Then configure behaviour with spring.flyway.*.
Set baseline-on-migrate=true only when adopting Flyway on an existing database that already has tables.
Use the real credentials from configuration or a secret store rather than literals.
Nothing replaces it, because it never existed. You name the SQL file correctly, for example V4__add_orders.sql, and put it in a configured location.
Version it by class name, such as V3__Something. Flyway sorts SQL and Java migrations together by version.
Do not change versioned migrations after they are applied, because the checksum no longer matches. Create a new versioned migration, or use flyway repair only when you understand the consequences.
Undo migrations are a feature of the paid editions. In the community edition, write a new forward migration that reverses the change.
Flyway uses naming conventions and base classes rather than a @SqlMigration annotation. Write versioned and repeatable SQL files in db/migration, use BaseJavaMigration for logic-heavy changes, add the database module for Flyway 10 and later, and let Spring Boot run migrations at startup through spring.flyway.*.