Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start Flyway migration from specific version

I try use flyway for migration. I find this option

spring.flyway.target= # Target version up to which migrations should be considered.

But I need set version with which to start migration. For exmple I need start migration from V3_foo.sql

Can I do it?

Briefly why I need it. I have a database with data. No migration tools have been used before. Everything was done manually. Now I have created an init.sql and placed in it the creation of the entire base structure. Now, when adding changes, I will start the migration from version 2. And if you need to run on a new empty database - from version 1

like image 836
ip696 Avatar asked Dec 03 '18 12:12

ip696


1 Answers

Baseline is the flyway feature you need.

If your case, baseline your database with flyway.baselineVersion=2 will tell flyway that your database is already at the version 2. Any subsequent flyway migrate will only process migrations greater than 2.

Note: If previous migrations failed, it may be necessary to drop table flyway_schema_history first.

like image 186
Benoit Avatar answered Oct 12 '22 20:10

Benoit