Is there a way to tell flyway to migrate only to specific version? For e.g. I have 4 versions e.g. V1
, V2
, V3
and V4
scripts and I want to migrate only to V3
but not to v4.
Asked
Active
Viewed 1.8k times
16

moffeltje
- 4,521
- 4
- 33
- 57

CrazyCoder
- 2,465
- 8
- 36
- 57
3 Answers
9
The migrate Task has a "target" attribute which lets you specify that.
target - The target version up to which Flyway should consider migrations. Migrations with a higher version number will be ignored. The special value current designates the current version of the schema.
Doc for CommandLine: https://flywaydb.org/documentation/usage/commandline/migrate
Example for maven
mvn -Dflyway.target=5.1 flyway:migrate

Slettal
- 1,007
- 13
- 19
-
2It would be nice if you add usage examples to your answer. – naXa stands with Ukraine Dec 18 '17 at 09:28
-
6mvn -Dflyway.target=5.1 flyway:migrate – DmitrySandalov Jun 15 '18 at 10:40
-
1The link doesn't work anymore, new one: https://flywaydb.org/documentation/usage/commandline/migrate – Jorge Guillermo Negrete Oct 11 '21 at 00:49
8
In case you use flyway command line and you want to migrate only to V3 you should do something like this:
flyway -configFiles=myconf.conf -target=3 migrate

Erica
- 1,608
- 2
- 21
- 32
3
If you would like to test you migrations, you can use Java API:
@Test
public void test() {
final FluentConfiguration fluentConfiguration = Flyway.configure()
.dataSource(dataSource);
fluentConfiguration.target("3") // stable version
.load()
.migrate();
// ... your SQL injection queries
fluentConfiguration
.target("latest") // remaining versions you need to test
.load()
.migrate();
// ... your SQL select checks
}

Praytic
- 1,771
- 4
- 21
- 41