How to add flyway migration in spring boot
keypoints about how to add flyway migration in spring boot
1- add dependency:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.flywaydb/flyway-database-postgresql -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
<version>11.3.3</version>
<scope>runtime</scope>
</dependency>
note that here we are using postgres that's why we used it. you need to add database dependency of which you are using.
2- set up properties
spring.flyway.enabled=false
spring.flyway.locations=classpath:db/migration
spring.flyway.baseline-on-migrate=true
spring.flyway.baseline-version=0
3- add following configuration in java code:
@Autowired
public void FlywayConfiguration(DataSource dataSource) {
Flyway.configure().baselineOnMigrate(true).dataSource(dataSource).load().migrate();
}
4- as configured in properties file, add migration sql script in db/migration directory with file name of this format "Vx__file_name.sql'' where x is number of migration like 1,2,3 etc